import { _ as _define_property } from "@swc/helpers/_/_define_property";
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import React from "react";
import classNames from "classnames";
import { ComponentDefaults } from "../../utils/typings";
import { usePropsValue } from "../../hooks/use-props-value";
import { useRtl } from "../configprovider";
var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
    disabled: false,
    activeText: '',
    inactiveText: ''
});
export var Switch = function(props) {
    var _ref = _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 = _object_without_properties(_ref, [
        "checked",
        "defaultChecked",
        "disabled",
        "activeText",
        "inactiveText",
        "className",
        "style",
        "onChange"
    ]);
    var classPrefix = 'nut-switch';
    var rtl = useRtl();
    var _usePropsValue = _sliced_to_array(usePropsValue({
        value: checked,
        defaultValue: defaultChecked
    }), 2), value = _usePropsValue[0], setValue = _usePropsValue[1];
    var classes = function() {
        var _obj;
        return classNames([
            classPrefix,
            className,
            (_obj = {}, _define_property(_obj, "".concat(classPrefix, "-close"), !value), _define_property(_obj, "".concat(classPrefix, "-disabled"), disabled), _define_property(_obj, "".concat(classPrefix, "-disabled-close"), disabled && !value), _obj)
        ]);
    };
    var onClick = function(event) {
        if (disabled) return;
        onChange && onChange(!value, event);
        setValue(!value);
    };
    var _obj, _obj1;
    return /*#__PURE__*/ React.createElement("div", _object_spread({
        className: classes(),
        onClick: function(e) {
            return onClick(e);
        },
        style: style
    }, rest), /*#__PURE__*/ React.createElement("div", {
        className: classNames([
            [
                "".concat(classPrefix, "-button")
            ],
            [
                value ? "".concat(classPrefix, "-button-open") : "".concat(classPrefix, "-button-close")
            ],
            (_obj = {}, _define_property(_obj, "".concat(classPrefix, "-button-open-rtl"), rtl && value), _define_property(_obj, "".concat(classPrefix, "-button-close-rtl"), rtl && !value), _obj)
        ])
    }, !value && !activeText && /*#__PURE__*/ React.createElement("div", {
        className: "".concat(classPrefix, "-close-line")
    })), activeText && /*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(classPrefix, "-label"), (_obj1 = {}, _define_property(_obj1, "".concat(classPrefix, "-label-open"), value), _define_property(_obj1, "".concat(classPrefix, "-label-close"), !value), _define_property(_obj1, "".concat(classPrefix, "-label-open-rtl"), rtl && value), _define_property(_obj1, "".concat(classPrefix, "-label-close-rtl"), rtl && !value), _define_property(_obj1, "".concat(classPrefix, "-label-close-disabled"), disabled && !value), _obj1))
    }, value ? activeText : inactiveText));
};
Switch.displayName = 'NutSwitch';
