"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var focus_1 = require("@dojo/framework/core/middleware/focus");
var vdom_1 = require("@dojo/framework/core/vdom");
var util_1 = require("../common/util");
var theme_1 = require("../middleware/theme");
var css = require("../theme/default/radio.m.css");
var label_1 = require("../label");
var factory = vdom_1.create({ focus: focus_1.focus, theme: theme_1.default })
    .properties()
    .children();
exports.Radio = factory(function Radio(_a) {
    var properties = _a.properties, id = _a.id, children = _a.children, _b = _a.middleware, focus = _b.focus, theme = _b.theme;
    var _c = properties(), _d = _c.aria, aria = _d === void 0 ? {} : _d, _e = _c.checked, checked = _e === void 0 ? false : _e, classes = _c.classes, disabled = _c.disabled, labelHidden = _c.labelHidden, name = _c.name, onBlur = _c.onBlur, onFocus = _c.onFocus, onOut = _c.onOut, onOver = _c.onOver, onValue = _c.onValue, readOnly = _c.readOnly, required = _c.required, themeProp = _c.theme, valid = _c.valid, value = _c.value, variant = _c.variant, widgetId = _c.widgetId;
    var themeCss = theme.classes(css);
    var idBase = widgetId || "radio-" + id;
    var _f = tslib_1.__read(children(), 1), labelChildren = _f[0];
    var label = util_1.isRenderResult(labelChildren) ? labelChildren : labelChildren.label;
    return (vdom_1.tsx("div", { key: "root", classes: [
            theme.variant(),
            themeCss.root,
            checked ? themeCss.checked : null,
            disabled ? themeCss.disabled : null,
            focus.isFocused('root') ? themeCss.focused : null,
            valid === false ? themeCss.invalid : null,
            valid === true ? themeCss.valid : null,
            readOnly ? themeCss.readonly : null,
            required ? themeCss.required : null
        ] },
        vdom_1.tsx("div", { classes: themeCss.inputWrapper },
            vdom_1.tsx("input", tslib_1.__assign({ id: idBase }, util_1.formatAriaProperties(aria), { classes: themeCss.input, checked: checked, disabled: disabled, focus: focus.shouldFocus(), "aria-invalid": valid === false ? 'true' : undefined, name: name, readonly: readOnly, "aria-readonly": readOnly === true ? 'true' : undefined, required: required, type: "radio", value: value, onblur: function () { return onBlur && onBlur(); }, onchange: function (event) {
                    event.stopPropagation();
                    var radio = event.target;
                    onValue(radio.checked);
                }, onfocus: function () { return onFocus && onFocus(); }, onpointerenter: function () { return onOver && onOver(); }, onpointerleave: function () { return onOut && onOut(); } })),
            vdom_1.tsx("div", { classes: themeCss.radioBackground },
                vdom_1.tsx("div", { classes: themeCss.radioOuter }),
                vdom_1.tsx("div", { classes: themeCss.radioInner }))),
        children().length > 0 && (vdom_1.tsx(label_1.default, { key: "label", classes: classes, theme: themeProp, disabled: disabled, focused: focus.isFocused('root'), forId: idBase, valid: valid, readOnly: readOnly, hidden: labelHidden, required: required, secondary: true, variant: variant }, label))));
});
exports.default = exports.Radio;

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