"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
            t[p[i]] = s[p[i]];
    return t;
};
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;
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importStar(require("react"));
const icons_1 = require("../../../assets/images/icons");
const Text_1 = require("../../Text");
const Context_1 = require("../Context");
const sc = __importStar(require("./styles"));
exports.Radio = props => {
    const { checked: checkedProp, name: nameProp, onChange, label } = props, other = __rest(props, ["checked", "name", "onChange", "label"]);
    const radioGroup = react_1.useContext(Context_1.Context);
    let checked = checkedProp;
    let name = nameProp;
    const handleChange = (event) => {
        if (onChange) {
            onChange(event);
        }
        if (radioGroup) {
            radioGroup.onChange(event);
        }
    };
    if (radioGroup) {
        if (typeof checked === 'undefined') {
            checked = radioGroup.value === props.value;
        }
        if (typeof name === 'undefined') {
            name = radioGroup.name;
        }
    }
    return (react_1.default.createElement(sc.Wrapper, { as: "label" },
        react_1.default.createElement(sc.Input, Object.assign({ type: "radio", name: name, checked: checked, onChange: handleChange }, other)),
        react_1.default.createElement(sc.Icon, { Asset: icons_1.SvgDot, scale: 1, width: 20, height: 20, color: "brandMain", checked: checked }),
        react_1.default.createElement(Text_1.Text, { color: "highlightText", ml: "s" }, label)));
};
//# sourceMappingURL=index.js.map