"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 Switch_1 = tslib_1.__importDefault(require("@material-ui/core/Switch"));
const react_1 = tslib_1.__importDefault(require("react"));
const component_mapper_1 = require("@bluebase/component-mapper");
const styles_1 = require("./styles");
const withPropsStyles_1 = require("../../withPropsStyles");
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.Switch = withPropsStyles_1.withPropsStyles(styles_1.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 (classes.color) {
        delete common.color;
    }
    const { label: labelClass, labelPlacementStart } = classes, switchClasses = tslib_1.__rest(classes, ["label", "labelPlacementStart"]);
    const node = (react_1.default.createElement(Switch_1.default, Object.assign({ classes: switchClasses }, common)));
    if (!label) {
        return node;
    }
    return (react_1.default.createElement(FormControlLabel_1.default, Object.assign({}, common, { label: label, labelPlacement: labelPlacement, control: node, classes: { label: labelClass, labelPlacementStart } })));
});
