(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "tslib", "react", "../typography/P2", "./style"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var tslib_1 = require("tslib");
    var react_1 = (0, tslib_1.__importStar)(require("react"));
    var P2_1 = (0, tslib_1.__importDefault)(require("../typography/P2"));
    var style_1 = require("./style");
    var Switch = function (_a) {
        var isChecked = _a.isChecked, isDisabled = _a.isDisabled, className = _a.className, hasTextOrIcon = _a.hasTextOrIcon, onChange = _a.onChange, iconBefore = _a.iconBefore, iconAfter = _a.iconAfter, textAfter = _a.textAfter, textBefore = _a.textBefore, isIndeterminate = _a.isIndeterminate, textDisabled = _a.textDisabled, _b = _a.testId, testId = _b === void 0 ? "switch" : _b, props = (0, tslib_1.__rest)(_a, ["isChecked", "isDisabled", "className", "hasTextOrIcon", "onChange", "iconBefore", "iconAfter", "textAfter", "textBefore", "isIndeterminate", "textDisabled", "testId"]);
        var handleChange = function (evt) {
            onChange && onChange(evt, !isChecked);
        };
        var renderBefore = function () {
            if (hasTextOrIcon && !isIndeterminate) {
                if (isChecked) {
                    if (iconBefore) {
                        return (0, react_1.cloneElement)(iconBefore, {
                            className: "beforeSVG",
                            width: 12
                        });
                    }
                    return (react_1.default.createElement(style_1.TextBefore, null,
                        react_1.default.createElement(P2_1.default, { as: "div", type: "cetus" }, textBefore ? textBefore : "Вкл.")));
                }
            }
            return null;
        };
        var renderAfter = function () {
            if (hasTextOrIcon && !isIndeterminate) {
                if (!isChecked) {
                    if (iconAfter) {
                        return (0, react_1.cloneElement)(iconAfter, {
                            className: "afterSVG",
                            width: 12
                        });
                    }
                    return (react_1.default.createElement(style_1.TextAfter, null,
                        react_1.default.createElement(P2_1.default, { as: "div", type: "cetus" }, isDisabled ? textDisabled || "н/д" : textAfter || "Выкл.")));
                }
            }
            return null;
        };
        return (react_1.default.createElement(style_1.SwitchComponent, (0, tslib_1.__assign)({ className: className, "data-testid": testId }, props),
            react_1.default.createElement(style_1.SwitchWrapper, { isDisabled: isDisabled, isChecked: isChecked, hasTextOrIcon: hasTextOrIcon, iconAfter: iconAfter, isIndeterminate: isIndeterminate, iconBefore: iconBefore, onClick: handleChange },
                renderBefore(),
                react_1.default.createElement(style_1.SwitchInput, { "data-testid": testId + "-input", "data-element": "switch-input", type: "checkbox", checked: isChecked, name: "checkbox", readOnly: true }),
                isIndeterminate ? (react_1.default.createElement(style_1.SwitchSliderIndeterminate, null)) : (react_1.default.createElement(style_1.SwitchSlider, { "data-element": "switch-slider", isChecked: isChecked, isDisabled: isDisabled, hasTextOrIcon: hasTextOrIcon })),
                renderAfter())));
    };
    exports.default = Switch;
});
