'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _relation = require('../mixins/relation');

exports['default'] = {
    name: 'SnCheckboxGroup',
    mixins: [(0, _relation.ParentMixin)('snCheckbox')],

    props: {
        max: [Number, String],
        disabled: Boolean,
        iconSize: [Number, String],
        checkedColor: String,
        value: {
            type: Array,
            'default': function _default() {
                return [];
            }
        },
        justify: {
            type: String,
            validator: function validator(value) {
                return ['between', 'around'].indexOf(value) > -1;
            }
        },
        type: {
            type: String,
            'default': '',
            validator: function validator(value) {
                return ['', 'card'].indexOf(value) > -1;
            }
        }
    },

    watch: {
        value: function value(val) {
            this.$emit('change', val);
        }
    },

    methods: {
        // @exposed-api
        toggleAll: function toggleAll(checked) {
            if (checked === false) {
                this.$emit('input', []);
                return;
            }

            var children = this.children;

            if (!checked) {
                children = children.filter(function (item) {
                    return !item.checked;
                });
            }

            var names = children.map(function (item) {
                return item.name;
            });
            this.$emit('input', names);
        }
    },

    render: function render() {
        var h = arguments[0];
        var type = this.type,
            $slots = this.$slots;

        var classnames = {
            'sn-checkbox-group': true
        };
        if (type) {
            classnames['sn-checkbox-group-' + type] = true;
        }

        return h(
            'div',
            { 'class': classnames },
            [$slots['default']]
        );
    }
};
module.exports = exports.default;