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