"use strict";
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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Switch = exports.SwitchBase = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const core_1 = require("../core");
const utils_1 = require("../utils");
const context_1 = require("./context");
const switchButton_1 = require("./switchButton");
const switchLabel_1 = require("./switchLabel");
exports.SwitchBase = core_1.styled.labelBox `
  align-items: center;
  cursor: pointer;
  display: inline-flex;
  line-height: normal;
  width: fit-content;

  &[aria-disabled='true'] {
    cursor: not-allowed;

    .vui-switchLabel {
      color: disabled.color;
    }
  }
`;
/**
 * Displays a toggle button with supporting text. Allows passing custom elements as side labels and inner labels.
 * Forwards many relevant props to the innner input element. Exposes some props to the children via context.
 */
exports.Switch = (0, core_1.vui)((props, ref) => {
    var _a;
    const { button, checked, children, className, defaultChecked, disabled, id, innerLabelOff, innerLabelOn, inputProps, inputRef, labelLeft, labelRight, name, onBlur, onChange, onFocus, required, size, value, variant } = props, rest = __rest(props, ["button", "checked", "children", "className", "defaultChecked", "disabled", "id", "innerLabelOff", "innerLabelOn", "inputProps", "inputRef", "labelLeft", "labelRight", "name", "onBlur", "onChange", "onFocus", "required", "size", "value", "variant"]);
    const styles = (0, core_1.useStyleConfig)('Switch', props);
    const context = (0, react_1.useMemo)(() => (0, utils_1.filterUndefined)({
        checked,
        defaultChecked,
        disabled,
        name,
        onBlur,
        onChange,
        onFocus,
        required,
        size,
        value,
        variant,
    }), [checked, defaultChecked, disabled, name, onBlur, onChange, onFocus, required, size, value, variant]);
    const aliasedProps = (0, utils_1.filterUndefined)({
        'aria-disabled': disabled,
    });
    return ((0, jsx_runtime_1.jsx)(context_1.SwitchProvider, { value: context, children: (0, jsx_runtime_1.jsxs)(exports.SwitchBase, Object.assign({ className: (0, utils_1.cs)('vui-switch', className), ref: ref }, styles.container, aliasedProps, rest, { children: [(0, utils_1.isReactText)(labelLeft) ? (0, jsx_runtime_1.jsx)(switchLabel_1.SwitchLabel, { mr: 1, text: labelLeft }) : labelLeft, (_a = children !== null && children !== void 0 ? children : button) !== null && _a !== void 0 ? _a : (0, jsx_runtime_1.jsx)(switchButton_1.SwitchButton, { id, innerLabelOff, innerLabelOn, inputProps, inputRef }), (0, utils_1.isReactText)(labelRight) ? (0, jsx_runtime_1.jsx)(switchLabel_1.SwitchLabel, { ml: 1, text: labelRight }) : labelRight] })) }));
});
exports.Switch.Button = switchButton_1.SwitchButton;
exports.Switch.Label = switchLabel_1.SwitchLabel;
exports.Switch.displayName = 'Switch';
exports.default = exports.Switch;
//# sourceMappingURL=switchMain.js.map