"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const RadixSlider = require("@radix-ui/react-slider");
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 radixDialog = require("../../workarounds/radixDialog.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("./rangeInput.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 RadixSlider__namespace = /* @__PURE__ */ _interopNamespaceDefault(RadixSlider);
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
const RangeInput = React__namespace.forwardRef(({ bind, className, disabled, onChange, label, labelClassName, labelId, scrollValidationErrorsIntoView, statusClassName, validationErrorsClassName, validationErrorMessages, displaySize, min, max, value, validationMode, step, required, customThumb, requiredIndicator, autoValidate, ...nativeProps }, ref) => {
  var _a;
  const [boundValue, setBoundValue, bindConfig] = useBindingState.useBindingState(bind, {
    value,
    onChange,
    validationErrorMessages,
    validationMode,
    autoValidate
  });
  const globals = config_context.useArmstrongConfig({
    scrollValidationErrorsIntoView,
    validationMode: bindConfig.validationMode,
    inputDisplaySize: displaySize,
    requiredIndicator,
    autoValidate: bindConfig.autoValidate,
    validationErrorIcon: bindConfig.validationErrorIcon
  });
  const generatedLabelId = React__namespace.useId();
  const finalLabelId = labelId ?? generatedLabelId;
  useDidUpdateEffect.useDidUpdateEffect(() => {
    if (globals.autoValidate && bindConfig.isTouched) {
      bindConfig.validate();
    }
  }, [boundValue]);
  const onBlurEvent = React__namespace.useCallback((event) => {
    if (globals.autoValidate && !bindConfig.isTouched) {
      bindConfig.validate();
    }
    radixDialog.onBlurWorkaround(event);
    bindConfig.setTouched(true);
  }, [bindConfig, globals.autoValidate]);
  return jsxRuntime.jsxs(statusWrapper_component.StatusWrapper, { className: classNames.concat(statusClassName, "arm-range-input-base"), validationMode: bindConfig.validationMode, errorIcon: bindConfig.validationErrorIcon, children: [label && jsxRuntime.jsx(label_component.Label, { id: finalLabelId, className: classNames.concat("arm-range-input-label", labelClassName), "data-disabled": disabled, required, displaySize: globals.inputDisplaySize, requiredIndicator: globals.requiredIndicator, children: label }), jsxRuntime.jsxs(RadixSlider__namespace.Root, { className: classNames.concat(className, "arm-range-input-root"), ...nativeProps, max, min, step, ref, disabled, "data-size": globals.inputDisplaySize, "aria-labelledby": finalLabelId, value: boundValue ? [boundValue] : void 0, onValueChange: (v) => setBoundValue(v == null ? void 0 : v[0]), children: [jsxRuntime.jsx(RadixSlider__namespace.Track, { className: "arm-range-input-track", children: jsxRuntime.jsx(RadixSlider__namespace.Range, { className: "arm-range-input-range" }) }), jsxRuntime.jsx(RadixSlider__namespace.Thumb, { className: "arm-range-input-thumb", "aria-label": typeof label === "string" ? label : void 0, onBlur: onBlurEvent, children: customThumb })] }), !!((_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 })] });
});
RangeInput.displayName = "RangeInput";
exports.RangeInput = RangeInput;
//# sourceMappingURL=rangeInput.component.cjs.map
