"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const reactCheckbox = require("@radix-ui/react-checkbox");
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 statusWrapper_component = require("../statusWrapper/statusWrapper.component.cjs");
const validationErrors_component = require("../validationErrors/validationErrors.component.cjs");
require("./checkbox.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 Checkbox = React__namespace.forwardRef(({ bind, checked, customIndicator, className, customIndeterminateIndicator, disabled, onCheckedChange, label, labelClassName, labelId, scrollValidationErrorsIntoView, statusClassName, testId, validationErrorsClassName, validationErrorMessages, validationMode, displaySize, required, requiredIndicator, statusPosition, autoValidate, ...nativeProps }, ref) => {
  var _a;
  const reactId = React__namespace.useId();
  const id = nativeProps.id ?? reactId;
  const [boundValue, setBoundValue, bindConfig] = useBindingState.useBindingState(bind, {
    value: checked,
    onChange: onCheckedChange,
    validationErrorMessages,
    validationMode,
    autoValidate
  });
  const globals = config_context.useArmstrongConfig({
    scrollValidationErrorsIntoView,
    checkboxCustomIndicator: customIndicator,
    checkboxCustomIndeterminateIndicator: customIndeterminateIndicator,
    requiredIndicator,
    inputStatusPosition: statusPosition,
    validationMode: bindConfig.validationMode,
    autoValidate: bindConfig.autoValidate,
    inputDisplaySize: displaySize
  });
  const onCheckedChangeInternal = React__namespace.useCallback((newValue) => {
    setBoundValue == null ? void 0 : setBoundValue(newValue);
  }, [setBoundValue]);
  useDidUpdateEffect.useDidUpdateEffect(() => {
    if (globals.autoValidate) {
      bindConfig.validate();
    }
    bindConfig.setTouched(true);
  }, [boundValue]);
  const indicator = React__namespace.useMemo(() => {
    switch (boundValue) {
      case "indeterminate":
        return globals.checkboxCustomIndeterminateIndicator;
      default:
        return globals.checkboxCustomIndicator;
    }
  }, [boundValue, globals.checkboxCustomIndicator, globals.checkboxCustomIndeterminateIndicator]);
  return jsxRuntime.jsxs(statusWrapper_component.StatusWrapper, { className: classNames.concat(statusClassName, "arm-input-base"), validationMode: bindConfig.validationMode, errorIcon: bindConfig.validationErrorIcon, statusPosition: globals.inputStatusPosition, children: [jsxRuntime.jsxs("div", { className: classNames.concat("arm-checkbox-container", className), "data-disabled": !!disabled, "data-testid": testId, "data-size": globals.inputDisplaySize, ...nativeProps, children: [jsxRuntime.jsx(reactCheckbox.Root, { className: "arm-checkbox", disabled, id, checked: boundValue ?? void 0, onCheckedChange: onCheckedChangeInternal, ref, children: jsxRuntime.jsx(reactCheckbox.Indicator, { className: "arm-checkbox-indicator", children: indicator }) }), label && jsxRuntime.jsx(label_component.Label, { className: classNames.concat("arm-checkbox-label", labelClassName), "data-disabled": !!disabled, htmlFor: id, required, requiredIndicator: globals.requiredIndicator, displaySize: globals.inputDisplaySize, children: label })] }), !!((_a = bindConfig.validationErrorMessages) == null ? void 0 : _a.length) && bindConfig.shouldShowValidationErrorMessage && jsxRuntime.jsx(validationErrors_component.ValidationErrors, { className: validationErrorsClassName, validationMode: globals.validationMode, validationErrors: bindConfig.validationErrorMessages, scrollIntoView: globals.scrollValidationErrorsIntoView })] });
});
Checkbox.displayName = "Checkbox";
exports.Checkbox = Checkbox;
//# sourceMappingURL=checkbox.component.cjs.map
