import { jsxs, jsx } from 'react/jsx-runtime';
import { forwardRef, useId } from 'react';
import { c as cn } from './utils-DdHUxIdC.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 (jsxs("div", { className: cn("flex gap-2", helpText ? "items-start" : "items-center", className), children: [jsx(RadioGroupItem$1, { ref: ref, id: id, value: value, "aria-describedby": helpText ? helpTextId : undefined, className: helpText ? "mt-0.5" : undefined, ...props }), (label || helpText) && (jsxs("div", { className: "flex flex-col gap-0.5", children: [label && (jsx(Label, { htmlFor: id, className: "cursor-pointer font-normal", children: label })), helpText && (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 = (jsx(RadioGroup$1, { ref: ref, disabled: disabled, required: required, "aria-invalid": !!error || undefined, "aria-describedby": [error ? errorId : null, helpText ? helpTextId : null]
            .filter(Boolean)
            .join(" ") || undefined, orientation: 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: children }));
    if (!hasField) {
        return radioGroup;
    }
    return (jsxs(Field, { "data-disabled": disabled || undefined, "data-invalid": !!error || undefined, className: className, children: [(label || helpText) && (jsxs("div", { children: [label && (jsxs(FieldLabel, { children: [label, required && (jsx("span", { "aria-hidden": "true", className: "text-destructive", children: "*" }))] })), helpText && (jsx(FieldDescription, { id: helpTextId, children: helpText }))] })), jsxs(FieldContent, { children: [radioGroup, !!error && jsx(FieldError, { id: errorId, children: error })] })] }));
});
RadioGroupRoot.displayName = "RadioGroup";
const RadioGroup = Object.assign(RadioGroupRoot, {
    Item: RadioGroupItem,
});

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