import { CheckboxMixin } from '../mixins/checkbox';

export default {
    name: 'SnRadio',

    mixins: [CheckboxMixin({
        role: 'radio',
        parent: 'snRadio'
    })],

    computed: {
        currentValue: {
            get: function get() {
                return this.parent ? this.parent.value : this.value;
            },
            set: function set(val) {
                (this.parent || this).$emit('input', val);
            }
        },

        checked: function checked() {
            return this.currentValue === this.name;
        }
    },

    methods: {
        toggle: function toggle() {
            if (this.currentValue === this.name) {
                this.currentValue = '';
            } else {
                this.currentValue = this.name;
            }
        }
    }
};