(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "tslib", "react", "../ListItem", "../../../hooks/useStateProps", "../../../CheckBox", "../List"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var tslib_1 = require("tslib");
    var react_1 = (0, tslib_1.__importStar)(require("react"));
    var ListItem_1 = (0, tslib_1.__importDefault)(require("../ListItem"));
    var useStateProps_1 = require("../../../hooks/useStateProps");
    var CheckBox_1 = (0, tslib_1.__importDefault)(require("../../../CheckBox"));
    var List_1 = (0, tslib_1.__importDefault)(require("../List"));
    var DEFAULT_VALUE = [];
    var ListCheckBoxes = (0, react_1.forwardRef)(function (_a, ref) {
        var dataSource = _a.dataSource, onChange = _a.onChange, _b = _a.defaultValue, defaultValue = _b === void 0 ? DEFAULT_VALUE : _b, className = _a.className, style = _a.style, isDisabled = _a.isDisabled, header = _a.header, height = _a.height, width = _a.width, viewType = _a.viewType, isSelected = _a.isSelected, isShowSelectAll = _a.isShowSelectAll, styleItem = _a.styleItem, classNameItem = _a.classNameItem, _c = _a.size, size = _c === void 0 ? "l" : _c, onClickItem = _a.onClickItem, props = (0, tslib_1.__rest)(_a, ["dataSource", "onChange", "defaultValue", "className", "style", "isDisabled", "header", "height", "width", "viewType", "isSelected", "isShowSelectAll", "styleItem", "classNameItem", "size", "onClickItem"]);
        var _d = (0, tslib_1.__read)((0, useStateProps_1.useStateProps)(defaultValue), 2), value = _d[0], setValue = _d[1];
        var handleCLick = function (event, val) {
            var values = (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(value), false);
            if (values.includes(val)) {
                values.splice(values.indexOf(val), 1);
            }
            else {
                values.push(val);
            }
            setValue(values);
            onChange === null || onChange === void 0 ? void 0 : onChange(event, values);
            onClickItem === null || onClickItem === void 0 ? void 0 : onClickItem(event, val);
        };
        var handleSelectAll = function (event) {
            var values = (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(value), false);
            if (value.length === (dataSource === null || dataSource === void 0 ? void 0 : dataSource.length)) {
                values = [];
            }
            else {
                values = (dataSource === null || dataSource === void 0 ? void 0 : dataSource.map(function (item) { return item.value; })) || [];
            }
            setValue(values);
            onChange === null || onChange === void 0 ? void 0 : onChange(event, values);
        };
        var renderItem = function (item) { return (react_1.default.createElement(ListItem_1.default, (0, tslib_1.__assign)({}, item, { key: item.label, className: classNameItem, style: styleItem, isDisabled: isDisabled || item.isDisabled, onClick: function (event) { return handleCLick(event, item.value); }, isSelected: value.indexOf(item.value) !== -1, size: size, leadContent: react_1.default.createElement(CheckBox_1.default, { isDisabled: isDisabled || item.isDisabled, name: item.name, isChecked: value.indexOf(item.value) !== -1, onChange: function (event) { return handleCLick(event, item.value); } }) }), item.label)); };
        var renderSelectAllItems = function () { return (react_1.default.createElement(ListItem_1.default, { size: size, key: "selectAll", className: classNameItem, style: styleItem, isDisabled: isDisabled, onClick: function (event) { return handleSelectAll(event); }, isSelected: Boolean(value.length === (dataSource === null || dataSource === void 0 ? void 0 : dataSource.length)), leadContent: react_1.default.createElement(CheckBox_1.default, { isDisabled: isDisabled, isChecked: Boolean(value.length === (dataSource === null || dataSource === void 0 ? void 0 : dataSource.length)), onChange: function (event) { return handleSelectAll(event); } }) }, "\u0412\u044B\u0431\u0440\u0430\u0442\u044C \u0432\u0441\u0435")); };
        return (react_1.default.createElement(List_1.default, (0, tslib_1.__assign)({ ref: ref, header: header, height: height, width: width, viewType: viewType, isSelected: isSelected, isShowSelectAll: isShowSelectAll, className: className, style: style, size: size, dataSource: dataSource, renderItem: renderItem, renderSelectAllItems: renderSelectAllItems, isDisabled: isDisabled }, props)));
    });
    ListCheckBoxes.displayName = "ListCheckBoxes";
    exports.default = ListCheckBoxes;
});
