import { jsxs, jsx } from 'react/jsx-runtime';
import { forwardRef, useId } from 'react';
import { c as cn } from './utils-BJnb9o5c.js';
import { RadioGroupItem as RadioGroupItem$1, RadioGroup as RadioGroup$1 } from './primitives/RadioGroup.js';
import { Label } from './primitives/Label.js';
import { FieldDescription, Field, FieldLabel, FieldContent, FieldError } from './primitives/Field.js';

const RadioGroupItem = forwardRef(({ label, helpText, value, className, id: idProp, ...props }, ref) => {
  const generatedId = useId();
  const id = idProp ?? generatedId;
  const helpTextId = `helpText_${id}`;
  return /* @__PURE__ */ jsxs(
    "div",
    {
      className: cn(
        "flex gap-2",
        helpText ? "items-start" : "items-center",
        className
      ),
      children: [
        /* @__PURE__ */ jsx(
          RadioGroupItem$1,
          {
            ref,
            id,
            value,
            "aria-describedby": helpText ? helpTextId : void 0,
            className: helpText ? "mt-0.5" : void 0,
            ...props
          }
        ),
        (label || helpText) && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5", children: [
          label && /* @__PURE__ */ jsx(Label, { htmlFor: id, className: "cursor-pointer font-normal", children: label }),
          helpText && /* @__PURE__ */ jsx(FieldDescription, { id: helpTextId, children: helpText })
        ] })
      ]
    }
  );
});
RadioGroupItem.displayName = "RadioGroup.Item";
const RadioGroupRoot = forwardRef(
  ({
    label,
    error,
    helpText,
    orientation = "horizontal",
    className,
    disabled,
    required,
    children,
    ...props
  }, ref) => {
    const generatedId = useId();
    const errorId = `error_${generatedId}`;
    const helpTextId = `helpText_${generatedId}`;
    const hasField = !!(label || error || helpText);
    const radioGroup = /* @__PURE__ */ jsx(
      RadioGroup$1,
      {
        ref,
        disabled,
        required,
        "aria-invalid": !!error || void 0,
        "aria-describedby": [error ? errorId : null, helpText ? helpTextId : null].filter(Boolean).join(" ") || void 0,
        orientation,
        className: cn(
          "data-[orientation=vertical]:grid data-[orientation=vertical]:gap-2 data-[orientation=horizontal]:flex data-[orientation=horizontal]:flex-row data-[orientation=horizontal]:flex-wrap data-[orientation=horizontal]:items-center data-[orientation=horizontal]:gap-4",
          !hasField && className
        ),
        ...props,
        children
      }
    );
    if (!hasField) {
      return radioGroup;
    }
    return /* @__PURE__ */ jsxs(
      Field,
      {
        "data-disabled": disabled || void 0,
        "data-invalid": !!error || void 0,
        className,
        children: [
          (label || helpText) && /* @__PURE__ */ jsxs("div", { children: [
            label && /* @__PURE__ */ jsxs(FieldLabel, { children: [
              label,
              required && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "text-destructive", children: "*" })
            ] }),
            helpText && /* @__PURE__ */ jsx(FieldDescription, { id: helpTextId, children: helpText })
          ] }),
          /* @__PURE__ */ jsxs(FieldContent, { children: [
            radioGroup,
            !!error && /* @__PURE__ */ jsx(FieldError, { id: errorId, children: error })
          ] })
        ]
      }
    );
  }
);
RadioGroupRoot.displayName = "RadioGroup";
const RadioGroup = Object.assign(RadioGroupRoot, {
  Item: RadioGroupItem
});

export { RadioGroup as R };
//# sourceMappingURL=RadioGroup-BTemSonO.js.map
