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

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