import { __spreadArray } from "tslib";
import { CheckboxGroupDefaultProps } from './props';
import fmtEvent from '../../_util/fmtEvent';
import mixinValue from '../../mixins/value';
Component({
    props: CheckboxGroupDefaultProps,
    mixins: [
        mixinValue({
            transformValue: function (val) {
                var value = val || [];
                return {
                    needUpdate: true,
                    value: value,
                };
            },
        }),
    ],
    methods: {
        onChange: function (_, e) {
            if (this.props.disabled) {
                return;
            }
            var currentValue = this.getValue();
            var index = e.currentTarget.dataset.index;
            var value = this.props.options[index].value;
            if (currentValue.indexOf(value) > -1) {
                currentValue = currentValue.filter(function (v) { return v !== value; });
            }
            else {
                currentValue = __spreadArray(__spreadArray([], currentValue, true), [value], false);
            }
            if (!this.isControlled()) {
                this.update(currentValue);
            }
            if (this.props.onChange) {
                this.props.onChange(currentValue, fmtEvent(this.props, e));
            }
        },
    },
});
