"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Checkbox = 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 Checkbox_1 = tslib_1.__importDefault(require("@material-ui/core/Checkbox"));
const react_1 = tslib_1.__importDefault(require("react"));
const core_2 = require("@material-ui/core");
const component_mapper_1 = require("@bluebase/component-mapper");
Checkbox_1.default.displayName = 'Checkbox';
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: ({ onChange, onValueChange }) => (event, checked) => {
        if (onChange) {
            onChange(event, checked);
        }
        if (onValueChange) {
            onValueChange(event.target.value, checked);
        }
    },
};
exports.Checkbox = (props) => {
    const newProps = component_mapper_1.objectMapper(props, map, { rest: true, ignore: ['onValueChange'] });
    const { label, labelPlacement, indeterminate } = newProps, common = tslib_1.__rest(newProps, ["label", "labelPlacement", "indeterminate"]);
    const { theme } = core_1.useTheme();
    const classes = useStyles(Object.assign(Object.assign({}, props), { theme }));
    const node = react_1.default.createElement(Checkbox_1.default, Object.assign({ classes: classes, indeterminate: indeterminate }, common, { color: "default" }));
    if (!label) {
        return node;
    }
    return (react_1.default.createElement(FormControlLabel_1.default, Object.assign({}, common, { label: label, labelPlacement: labelPlacement, control: node })));
};
