"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const RadixRadioGroup = require("@radix-ui/react-radio-group");
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 options = require("../../types/options.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("./radioGroup.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 RadixRadioGroup__namespace = /* @__PURE__ */ _interopNamespaceDefault(RadixRadioGroup);
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
const RadioGroup = React__namespace.forwardRef(
  ({ bind, options: options$1, className, value, errorIcon, validationMode, validationErrorMessages, onChange, customIndicator, error, displaySize, label, labelClassName, required, disabled, scrollValidationErrorsIntoView, requiredIndicator, displayMode, validationErrorsClassName, labelId, autoValidate, ...nativeProps }, ref) => {
    const [boundValue, setBoundValue, bindConfig] = useBindingState.useBindingState(bind, {
      value,
      validationErrorMessages,
      validationErrorIcon: errorIcon,
      validationMode,
      onChange,
      autoValidate
    });
    const globals = config_context.useArmstrongConfig({
      validationMode: bindConfig.validationMode,
      requiredIndicator,
      scrollValidationErrorsIntoView,
      validationErrorIcon: bindConfig.validationErrorIcon,
      inputDisplaySize: displaySize,
      autoValidate: bindConfig.autoValidate
    });
    useDidUpdateEffect.useDidUpdateEffect(() => {
      if (globals.autoValidate) {
        bindConfig.validate();
      }
      bindConfig.setTouched(true);
    }, [boundValue]);
    return jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [label && jsxRuntime.jsx(label_component.Label, { id: labelId, className: classNames.concat("arm-radio-group-label", labelClassName), required, requiredIndicator: globals.requiredIndicator, displaySize: globals.inputDisplaySize, children: label }), jsxRuntime.jsx(RadixRadioGroup__namespace.Root, { className: classNames.concat("arm-radio-group", className), "data-error": error || !!(validationErrorMessages == null ? void 0 : validationErrorMessages.length), "data-disabled": disabled, "data-size": displaySize, "data-mode": displayMode, value: (boundValue == null ? void 0 : boundValue.toString()) ?? "undefined", onValueChange: (newValue) => setBoundValue(typeof boundValue === "number" && newValue !== null && newValue !== void 0 ? +newValue : newValue), disabled, ref, ...nativeProps, children: options$1.map((option, i) => {
      var _a, _b, _c;
      const isChecked = boundValue === option.id;
      const labelContent = options.getContentFromOption(option, isChecked);
      return jsxRuntime.jsxs("div", { className: "arm-radio-group-item-container", children: [jsxRuntime.jsx(RadixRadioGroup__namespace.Item, { ...option.htmlProps ?? {}, className: "arm-radio-group-item", value: ((_a = option.id) == null ? void 0 : _a.toString()) ?? "", id: (_b = option.id) == null ? void 0 : _b.toString(), disabled: option.disabled, "data-checked": isChecked, "data-index": i, children: displayMode === "radio" ? jsxRuntime.jsx(RadixRadioGroup__namespace.Indicator, { className: "arm-radio-group-item-indicator", "data-custom-icon": !!customIndicator, children: isChecked && customIndicator }) : labelContent }), displayMode === "radio" && jsxRuntime.jsx("label", { className: "arm-radio-label", htmlFor: (_c = option.id) == null ? void 0 : _c.toString(), children: labelContent })] }, option.id);
    }) }), bindConfig.shouldShowValidationErrorMessage && !!bindConfig.validationErrorMessages.length && jsxRuntime.jsx(validationErrors_component.ValidationErrors, { validationErrors: bindConfig.validationErrorMessages, className: classNames.concat("arm-radio-errors", validationErrorsClassName) })] });
  }
  // type assertion to ensure generic works with RefForwarded component
  // DO NOT CHANGE TYPE WITHOUT CHANGING THIS, FIND TYPE BY INSPECTING React.forwardRef
);
RadioGroup.defaultProps = {
  displayMode: "radio"
};
RadioGroup.displayName = "RadioGroup";
exports.RadioGroup = RadioGroup;
//# sourceMappingURL=radioGroup.component.cjs.map
