"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Switch = exports.SwitchPure = void 0;
var react_1 = __importStar(require("react"));
var styled_components_1 = require("styled-components");
var theme_interface_1 = require("../../types/theme.interface");
var styles_1 = require("../styles");
var SwitchCore_1 = require("./SwitchCore");
var Switch_style_1 = __importDefault(require("./Switch.style"));
exports.SwitchPure = react_1.default.forwardRef(function SwitchPure(props, inputRef) {
    var _a, _b, _c;
    var theme = styled_components_1.useTheme();
    var _d = (theme !== null && theme !== void 0 ? theme : {}).checkbox, checkbox = _d === void 0 ? {} : _d;
    var _e = checkbox, defaultColorTheme = _e.defaultColor, sizeTheme = _e.size, roundedTheme = _e.rounded;
    var title = props.title, color = props.color, checked = props.checked, _f = props.rounded, rounded = _f === void 0 ? roundedTheme : _f, _g = props.size, size = _g === void 0 ? sizeTheme !== null && sizeTheme !== void 0 ? sizeTheme : 24 : _g, _h = props.variant, variant = _h === void 0 ? 'primary' : _h, _j = props.valueTrue, valueTrue = _j === void 0 ? true : _j, _k = props.valueFalse, valueFalse = _k === void 0 ? false : _k, error = props.error, disabled = props.disabled, onChange = props.onChange, rest = __rest(props, ["title", "color", "checked", "rounded", "size", "variant", "valueTrue", "valueFalse", "error", "disabled", "onChange"]);
    var ref = react_1.useRef(null);
    react_1.useImperativeHandle(inputRef, function () { return ref.current; }, []);
    var checkboxColor = (_c = (_b = (_a = color !== null && color !== void 0 ? color : defaultColorTheme) !== null && _a !== void 0 ? _a : (theme !== null && theme !== void 0 ? theme : {})[variant]) !== null && _b !== void 0 ? _b : theme_interface_1.ThemeDefault[variant]) !== null && _c !== void 0 ? _c : theme_interface_1.ThemeDefault.primary;
    return (react_1.default.createElement(styles_1.FormStyle, null,
        react_1.default.createElement(Switch_style_1.default, { color: checkboxColor, rounded: rounded, size: size },
            react_1.default.createElement("div", { className: "checkbox-container clean" },
                react_1.default.createElement("label", { className: "checkbox-container clean" },
                    react_1.default.createElement("input", __assign({ ref: ref, type: "checkbox", checked: checked }, rest, { onChange: function (e) {
                            if (onChange)
                                onChange(e.currentTarget.checked ? valueTrue : valueFalse);
                        } })),
                    react_1.default.createElement("span", { className: "checkbox " + (error && 'has-error') + " " + (disabled && 'disabled'), "data-testid": "input-checkbox-error" }),
                    react_1.default.createElement("span", { className: "title " + (disabled && 'disabled') }, title))),
            error && (react_1.default.createElement("div", { className: "error-input", "data-testid": "input-error" }, error)))));
});
exports.Switch = react_1.default.forwardRef(function Checkbox(props, inputRef) {
    return react_1.default.createElement(SwitchCore_1.SwitchCore, __assign({}, props, { ref: inputRef, as: exports.SwitchPure }));
});
//# sourceMappingURL=Switch.js.map