"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Switch", {
    enumerable: true,
    get: function() {
        return Switch;
    }
});
var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
var _define_property = require("@swc/helpers/_/_define_property");
var _object_spread = require("@swc/helpers/_/_object_spread");
var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
var _object_without_properties = require("@swc/helpers/_/_object_without_properties");
var _sliced_to_array = require("@swc/helpers/_/_sliced_to_array");
var _react = /*#__PURE__*/ _interop_require_default._(require("react"));
var _classnames = /*#__PURE__*/ _interop_require_default._(require("classnames"));
var _typings = require("../../utils/typings");
var _usepropsvalue = require("../../hooks/use-props-value");
var _configprovider = require("../configprovider");
var defaultProps = (0, _object_spread_props._)((0, _object_spread._)({}, _typings.ComponentDefaults), {
    disabled: false,
    activeText: '',
    inactiveText: ''
});
var Switch = function Switch(props) {
    var _ref = (0, _object_spread._)({}, defaultProps, props), checked = _ref.checked, defaultChecked = _ref.defaultChecked, disabled = _ref.disabled, activeText = _ref.activeText, inactiveText = _ref.inactiveText, className = _ref.className, style = _ref.style, onChange = _ref.onChange, rest = (0, _object_without_properties._)(_ref, [
        "checked",
        "defaultChecked",
        "disabled",
        "activeText",
        "inactiveText",
        "className",
        "style",
        "onChange"
    ]);
    var classPrefix = 'nut-switch';
    var rtl = (0, _configprovider.useRtl)();
    var _usePropsValue = (0, _sliced_to_array._)((0, _usepropsvalue.usePropsValue)({
        value: checked,
        defaultValue: defaultChecked
    }), 2), value = _usePropsValue[0], setValue = _usePropsValue[1];
    var classes = function classes() {
        var _obj;
        return (0, _classnames.default)([
            classPrefix,
            className,
            (_obj = {}, (0, _define_property._)(_obj, "".concat(classPrefix, "-close"), !value), (0, _define_property._)(_obj, "".concat(classPrefix, "-disabled"), disabled), (0, _define_property._)(_obj, "".concat(classPrefix, "-disabled-close"), disabled && !value), _obj)
        ]);
    };
    var onClick = function onClick(event) {
        if (disabled) return;
        onChange && onChange(!value, event);
        setValue(!value);
    };
    var _obj, _obj1;
    return /*#__PURE__*/ _react.default.createElement("div", (0, _object_spread._)({
        className: classes(),
        onClick: function onClick1(e) {
            return onClick(e);
        },
        style: style
    }, rest), /*#__PURE__*/ _react.default.createElement("div", {
        className: (0, _classnames.default)([
            [
                "".concat(classPrefix, "-button")
            ],
            [
                value ? "".concat(classPrefix, "-button-open") : "".concat(classPrefix, "-button-close")
            ],
            (_obj = {}, (0, _define_property._)(_obj, "".concat(classPrefix, "-button-open-rtl"), rtl && value), (0, _define_property._)(_obj, "".concat(classPrefix, "-button-close-rtl"), rtl && !value), _obj)
        ])
    }, !value && !activeText && /*#__PURE__*/ _react.default.createElement("div", {
        className: "".concat(classPrefix, "-close-line")
    })), activeText && /*#__PURE__*/ _react.default.createElement("div", {
        className: (0, _classnames.default)("".concat(classPrefix, "-label"), (_obj1 = {}, (0, _define_property._)(_obj1, "".concat(classPrefix, "-label-open"), value), (0, _define_property._)(_obj1, "".concat(classPrefix, "-label-close"), !value), (0, _define_property._)(_obj1, "".concat(classPrefix, "-label-open-rtl"), rtl && value), (0, _define_property._)(_obj1, "".concat(classPrefix, "-label-close-rtl"), rtl && !value), (0, _define_property._)(_obj1, "".concat(classPrefix, "-label-close-disabled"), disabled && !value), _obj1))
    }, value ? activeText : inactiveText));
};
Switch.displayName = 'NutSwitch';
