"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Radio = void 0;
const tslib_1 = require("tslib");
const core_1 = require("@bluebase/core");
const FormControlLabel_1 = tslib_1.__importDefault(require("@material-ui/core/FormControlLabel"));
const Radio_1 = tslib_1.__importDefault(require("@material-ui/core/Radio"));
const react_1 = tslib_1.__importDefault(require("react"));
const lodash_get_1 = tslib_1.__importDefault(require("lodash.get"));
const core_2 = require("@material-ui/core");
const helpers_1 = require("../../helpers");
const component_mapper_1 = require("@bluebase/component-mapper");
const useStyles = core_2.makeStyles({
    checked: ({ color, theme }) => {
        // If color is undefined, then use defaults
        if (color === 'default') {
            return {};
        }
        // If color is undefined, then use defaults
        if (color === undefined) {
            color = theme.palette.secondary.main;
        }
        // If color is NOT primary, secondary or default then create custom styles
        if (color === 'primary' || color === 'secondary') {
            color = theme.palette[color].main;
        }
        return {
            color
        };
    },
    disabled: ({ theme }) => ({
        color: theme.palette.action.disabled,
    }),
});
const map = {
    onChange: (props) => (event, checked) => {
        const onChange = lodash_get_1.default(props, 'onChange', helpers_1.noop);
        const onValueChange = lodash_get_1.default(props, 'onValueChange', helpers_1.noop);
        onChange(event, checked);
        onValueChange(event.target.value, checked);
    },
};
exports.Radio = (props) => {
    const newProps = component_mapper_1.objectMapper(props, map, { rest: true, ignore: ['onValueChange'] });
    const { label, labelPlacement, color } = newProps, common = tslib_1.__rest(newProps, ["label", "labelPlacement", "color"]);
    const { theme } = core_1.useTheme();
    const classes = useStyles(Object.assign(Object.assign({}, props), { theme }));
    const node = react_1.default.createElement(Radio_1.default, Object.assign({ classes: classes }, common, { color: "default" }));
    if (!label) {
        return node;
    }
    return (react_1.default.createElement(FormControlLabel_1.default, Object.assign({}, common, { label: label, labelPlacement: labelPlacement, control: node })));
};
