"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const reactSwitch = require("@radix-ui/react-switch");
const React = require("react");
const useBindingState = require("../../form/hooks/useBindingState.cjs");
const classNames = require("../../utils/classNames.cjs");
require("../../utils/globals.cjs");
require("zod");
const useDidUpdateEffect = require("../../hooks/useDidUpdateEffect.cjs");
const config_context = require("../config/config.context.cjs");
const label_component = require("../label/label.component.cjs");
const validationErrors_component = require("../validationErrors/validationErrors.component.cjs");
require("./switch.theme.css.cjs");
function _interopNamespaceDefault(e) {
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
  if (e) {
    for (const k in e) {
      if (k !== "default") {
        const d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: () => e[k]
        });
      }
    }
  }
  n.default = e;
  return Object.freeze(n);
}
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
const Switch = React__namespace.forwardRef(
  ({ bind, checked, onCheckedChange, defaultChecked, disabled, className, labelClassName, label, validationErrorMessages, validationErrorsClassName, scrollValidationErrorsIntoView, validationMode, displaySize, labelId, required, requiredIndicator, autoValidate, ...nativeProps }, ref) => {
    const generatedId = React__namespace.useId();
    const id = nativeProps.id ?? generatedId;
    const [boundValue, setBoundValue, bindConfig] = useBindingState.useBindingState(bind, {
      value: checked,
      onChange: onCheckedChange,
      validationErrorMessages,
      validationMode,
      autoValidate
    });
    const globals = config_context.useArmstrongConfig({
      validationMode: bindConfig.validationMode,
      scrollValidationErrorsIntoView,
      inputDisplaySize: displaySize,
      requiredIndicator,
      autoValidate: bindConfig.autoValidate
    });
    const onCheckedChangeInternal = React__namespace.useCallback((newValue) => {
      setBoundValue == null ? void 0 : setBoundValue(newValue);
    }, [setBoundValue]);
    useDidUpdateEffect.useDidUpdateEffect(() => {
      if (globals.autoValidate) {
        bindConfig.validate();
      }
      bindConfig.setTouched(true);
    }, [boundValue]);
    return jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: classNames.concat("arm-switch-container", className), "data-disabled": disabled, children: [jsxRuntime.jsx(reactSwitch.Root, { ...nativeProps, className: "arm-switch", id, ref, disabled, defaultChecked, onCheckedChange: onCheckedChangeInternal, checked: boundValue ?? void 0, "data-size": globals.inputDisplaySize, children: jsxRuntime.jsx(reactSwitch.Thumb, { className: "arm-switch-nub" }) }), jsxRuntime.jsx(label_component.Label, { id: labelId, required, requiredIndicator: globals.requiredIndicator, className: classNames.concat(labelClassName, "arm-switch-label"), "data-disabled": disabled, htmlFor: id, displaySize: globals.inputDisplaySize, children: label })] }), bindConfig.validationErrorMessages && bindConfig.shouldShowValidationErrorMessage && jsxRuntime.jsx(validationErrors_component.ValidationErrors, { className: validationErrorsClassName, validationMode: globals.validationMode, validationErrors: bindConfig.validationErrorMessages, scrollIntoView: globals.scrollValidationErrorsIntoView })] });
  }
  // type assertion to ensure generic works with RefForwarded component
  // DO NOT CHANGE TYPE WITHOUT CHANGING THIS, FIND TYPE BY INSPECTING React.forwardRef
);
Switch.displayName = "Switch";
exports.Switch = Switch;
//# sourceMappingURL=switch.component.cjs.map
