"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Checkboxes_1 = require("./Checkboxes");
var theme_1 = require("../theme");
var react_1 = tslib_1.__importDefault(require("react"));
var uncontrollable_1 = tslib_1.__importDefault(require("uncontrollable"));
var Checkbox_1 = tslib_1.__importDefault(require("./Checkbox"));
var ListCheckboxes = /** @class */ (function (_super) {
    tslib_1.__extends(ListCheckboxes, _super);
    function ListCheckboxes() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    ListCheckboxes.prototype.renderOption = function (option, index) {
        var _this = this;
        var _a = this.props, labelClassName = _a.labelClassName, disabled = _a.disabled, cx = _a.classnames, itemClassName = _a.itemClassName, itemRender = _a.itemRender;
        var valueArray = this.valueArray;
        if (Array.isArray(option.children)) {
            return (react_1.default.createElement("div", { key: index, className: cx('ListCheckboxes-group', option.className) },
                react_1.default.createElement("div", { className: cx('ListCheckboxes-itemLabel') }, itemRender(option)),
                react_1.default.createElement("div", { className: cx('ListCheckboxes-items', option.className) }, option.children.map(function (child, index) {
                    return _this.renderOption(child, index);
                }))));
        }
        return (react_1.default.createElement("div", { key: index, className: cx('ListCheckboxes-item', itemClassName, option.className, disabled || option.disabled ? 'is-disabled' : ''), onClick: function () { return _this.toggleOption(option); } },
            react_1.default.createElement("div", { className: cx('ListCheckboxes-itemLabel') }, itemRender(option)),
            react_1.default.createElement(Checkbox_1.default, { checked: !!~valueArray.indexOf(option), disabled: disabled || option.disabled, labelClassName: labelClassName, description: option.description })));
    };
    ListCheckboxes.prototype.render = function () {
        var _this = this;
        var _a = this.props, value = _a.value, options = _a.options, className = _a.className, placeholder = _a.placeholder, cx = _a.classnames, option2value = _a.option2value;
        this.valueArray = Checkboxes_1.Checkboxes.value2array(value, options, option2value);
        var body = [];
        if (Array.isArray(options) && options.length) {
            body = options.map(function (option, key) { return _this.renderOption(option, key); });
        }
        return (react_1.default.createElement("div", { className: cx('ListCheckboxes', className) }, body && body.length ? (body) : (react_1.default.createElement("div", { className: cx('ListCheckboxes-placeholder') }, placeholder))));
    };
    return ListCheckboxes;
}(Checkboxes_1.Checkboxes));
exports.ListCheckboxes = ListCheckboxes;
exports.default = theme_1.themeable(uncontrollable_1.default(ListCheckboxes, {
    value: 'onChange'
}));
//# sourceMappingURL=./components/ListCheckboxes.js.map
