"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Switch = void 0;
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 react_native_1 = require("react-native");
const component_mapper_1 = require("@bluebase/component-mapper");
const styles_1 = require("./styles");
const styles_2 = require("@material-ui/core/styles");
Switch_1.default.displayName = 'Switch';
FormControlLabel_1.default.displayName = 'FormControlLabel';
const map = {
    onChange: ({ onChange, onValueChange }) => (event, checked) => {
        if (onChange) {
            onChange(event, checked);
        }
        if (onValueChange) {
            onValueChange(event.target.value, checked);
        }
    },
    checked: 'checked',
    classes: 'classes',
    disabled: 'disabled',
    id: 'id',
    label: 'label',
    labelPlacement: 'labelPlacement',
    name: 'name',
    style: ({ style }) => react_native_1.StyleSheet.flatten(style),
    value: 'value',
};
exports.Switch = styles_2.withStyles(styles_1.styles)((props) => {
    const newProps = component_mapper_1.objectMapper(props, map);
    const { label, labelPlacement, classes, color } = newProps, common = tslib_1.__rest(newProps, ["label", "labelPlacement", "classes", "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, { color: "default" }));
    if (!label) {
        return node;
    }
    return (react_1.default.createElement(FormControlLabel_1.default, Object.assign({}, common, { value: common.value, label: label, labelPlacement: labelPlacement, control: node, classes: { label: labelClass, labelPlacementStart } })));
});
