"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
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 component_mapper_1 = require("@bluebase/component-mapper");
const withPropsStyles_1 = require("../../withPropsStyles");
const styles = ({ color }, theme) => {
    // If color is NOT primary, secondary or default then create custom styles
    if (color === 'primary' || color === 'secondary' || color === 'default') {
        return {};
    }
    // If color is undefined, then use defaults
    if (color === undefined) {
        return {};
    }
    return {
        root: {
            // color,
            // tslint:disable-next-line: object-literal-sort-keys
            '&$checked': {
                color,
            },
            '&$disabled': {
                color: theme.palette.action.disabled,
            },
        },
        // tslint:disable-next-line: object-literal-sort-keys
        checked: {},
        disabled: {},
    };
};
const map = {
    // If color is primary, secondary or default set as is
    color: ({ color }) => {
        if (color === 'primary' || color === 'secondary' || color === 'default') {
            return color;
        }
        return;
    },
    onChange: ({ onChange, onValueChange }) => (event, checked) => {
        if (onChange) {
            onChange(event, checked);
        }
        if (onValueChange) {
            onValueChange(event.target.value, checked);
        }
    },
};
exports.Radio = withPropsStyles_1.withPropsStyles(styles)((props) => {
    const newProps = component_mapper_1.objectMapper(props, map, { rest: true, ignore: ['onValueChange'] });
    const { label, labelPlacement, classes } = newProps, common = tslib_1.__rest(newProps, ["label", "labelPlacement", "classes"]);
    if (Object.keys(classes).length > 0) {
        delete common.color;
    }
    const node = react_1.default.createElement(Radio_1.default, Object.assign({ classes: classes }, common));
    if (!label) {
        return node;
    }
    return (react_1.default.createElement(FormControlLabel_1.default, Object.assign({}, common, { label: label, labelPlacement: labelPlacement, control: node })));
});
