"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var Options_1 = require("./Options");
var cx = require("classnames");
var Checkbox_1 = require("../../components/Checkbox");
var chunk = require("lodash/chunk");
;
var CheckboxesControl = /** @class */ (function (_super) {
    tslib_1.__extends(CheckboxesControl, _super);
    function CheckboxesControl() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    CheckboxesControl.prototype.componentDidMount = function () {
        var _a = this.props, defaultCheckAll = _a.defaultCheckAll, onToggleAll = _a.onToggleAll;
        defaultCheckAll && onToggleAll();
    };
    CheckboxesControl.prototype.render = function () {
        var _a = this.props, className = _a.className, disabled = _a.disabled, placeholder = _a.placeholder, options = _a.options, inline = _a.inline, columnsCount = _a.columnsCount, selectedOptions = _a.selectedOptions, onToggle = _a.onToggle, onToggleAll = _a.onToggleAll, checkAll = _a.checkAll, ns = _a.classPrefix;
        var body = [];
        if (options) {
            body = options.map(function (option, key) { return (React.createElement(Checkbox_1.default, { classPrefix: ns, key: key, onChange: function () { return onToggle(option); }, checked: !!~selectedOptions.indexOf(option), disabled: disabled || option.disabled, inline: inline }, option.label)); });
        }
        if (checkAll && body.length) {
            body.unshift(React.createElement(Checkbox_1.default, { key: "checkall", classPrefix: ns, onChange: onToggleAll, checked: !!selectedOptions.length, partial: !!(selectedOptions.length && selectedOptions.length !== options.length), disabled: disabled, inline: inline }, "\u5168\u9009/\u4E0D\u9009"));
        }
        if (!inline && columnsCount > 1) {
            var weight = 12 / columnsCount;
            var cellClassName_1 = ns + "Grid-col--sm" + (weight === Math.round(weight) ? weight : '');
            body = chunk(body, columnsCount).map(function (group, groupIndex) { return (React.createElement("div", { className: ns + "Grid", key: groupIndex }, group.map(function (item, index) { return (React.createElement("div", { key: index, className: cellClassName_1 }, item)); }))); });
        }
        return (React.createElement("div", { className: cx(ns + "CheckboxesControl", className) }, body && body.length ? body : (React.createElement("span", { className: ns + "Form-placeholder" }, placeholder))));
    };
    CheckboxesControl.defaultProps = {
        columnsCount: 1,
        multiple: true,
        placeholder: '暂无选项'
    };
    return CheckboxesControl;
}(React.Component));
exports.default = CheckboxesControl;
var CheckboxesControlRenderer = /** @class */ (function (_super) {
    tslib_1.__extends(CheckboxesControlRenderer, _super);
    function CheckboxesControlRenderer() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    CheckboxesControlRenderer = tslib_1.__decorate([
        Options_1.OptionsControl({
            type: 'checkboxes',
            sizeMutable: false
        })
    ], CheckboxesControlRenderer);
    return CheckboxesControlRenderer;
}(CheckboxesControl));
exports.CheckboxesControlRenderer = CheckboxesControlRenderer;
;
//# sourceMappingURL=./renderers/Form/Checkboxes.js.map
