"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var vdom_1 = require("@dojo/framework/core/vdom");
var middleware_1 = require("./middleware");
var index_1 = require("../checkbox/index");
var theme_1 = require("../middleware/theme");
var css = require("../theme/default/checkbox-group.m.css");
var factory = vdom_1.create({ checkboxGroup: middleware_1.checkboxGroup, theme: theme_1.default })
    .properties()
    .children();
exports.CheckboxGroup = factory(function CheckboxGroup(_a) {
    var children = _a.children, properties = _a.properties, _b = _a.middleware, checkboxGroup = _b.checkboxGroup, theme = _b.theme;
    var _c = properties(), name = _c.name, options = _c.options, onValue = _c.onValue, initialValue = _c.initialValue, value = _c.value, classes = _c.classes, themeProp = _c.theme, variant = _c.variant, disabled = _c.disabled;
    var _d = tslib_1.__read(children(), 1), _e = _d[0], _f = _e === void 0 ? { checkboxes: undefined, label: undefined } : _e, checkboxes = _f.checkboxes, label = _f.label;
    var checkbox = checkboxGroup(onValue, initialValue, value);
    var _g = theme.classes(css), root = _g.root, legend = _g.legend;
    function renderCheckboxes() {
        if (checkboxes) {
            return checkboxes(name, checkbox, options, !!disabled);
        }
        return options.map(function (_a) {
            var value = _a.value, label = _a.label;
            var checked = checkbox(value).checked;
            return (vdom_1.tsx(index_1.Checkbox, { name: name, value: value, checked: checked(), onValue: checked, classes: classes, theme: themeProp, variant: variant, disabled: disabled }, label || value));
        });
    }
    return (vdom_1.tsx("fieldset", { key: "root", classes: [theme.variant(), root], name: name },
        label && vdom_1.tsx("legend", { classes: legend }, label),
        renderCheckboxes()));
});
exports.default = exports.CheckboxGroup;

/*# sourceMappingURL=index.js.map*/