"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = __importStar(require("react"));
var styled_components_1 = __importDefault(require("styled-components"));
var Button_1 = require("../Button");
var Input_1 = require("./Input");
var styleConstants_1 = require("../styleConstants");
exports.RadioButtonDiv = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n  input {\n    display: none;\n  }\n  input:checked + button {\n    background-color: ", ";\n    border: 1px solid ", ";\n    color: ", ";\n  }\n"], ["\n  input {\n    display: none;\n  }\n  input:checked + button {\n    background-color: ", ";\n    border: 1px solid ", ";\n    color: ", ";\n  }\n"])), styleConstants_1.colors.accent.CIVIL_BLUE, styleConstants_1.colors.accent.CIVIL_BLUE, styleConstants_1.colors.basic.WHITE);
exports.RadioButton = function (props) {
    var input;
    var onChange = props.onChange, children = props.children, name = props.name;
    var clickHandler = function () {
        input.checked = true;
        if (onChange) {
            onChange(props.name, input.value);
        }
    };
    var defaultChecked = props.defaultValue === props.value;
    return (React.createElement(exports.RadioButtonDiv, null,
        React.createElement("input", { type: "radio", value: props.value, defaultChecked: defaultChecked, name: name, ref: function (ref) { return (input = ref); } }),
        React.createElement(Button_1.SecondaryButton, { onClick: clickHandler, disabled: props.disabled }, children)));
};
var RadioDiv = styled_components_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n  > div {\n    display: flex;\n    flex-direction: rows;\n    flex-wrap: wrap;\n  }\n"], ["\n  > div {\n    display: flex;\n    flex-direction: rows;\n    flex-wrap: wrap;\n  }\n"])));
exports.RadioInput = function (props) {
    var defaultValue = props.defaultValue, onChange = props.onChange, label = props.label, name = props.name, inputRef = props.inputRef, children = props.children;
    var childrenWithProps = React.Children.map(children, function (child) {
        return React.cloneElement(child, { name: name, onChange: onChange, defaultValue: defaultValue });
    });
    return (React.createElement(RadioDiv, { ref: inputRef },
        label ? React.createElement(Input_1.InputLabel, null, label) : null,
        React.createElement("div", null, childrenWithProps)));
};
var templateObject_1, templateObject_2;
//# sourceMappingURL=RadioInput.js.map