import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { cn } from '../../../../scalars/lib/utils.js';
import { FormLabel } from '../../../../scalars/components/fragments/form-label/form-label.js';
import { FormMessageList } from '../../../../scalars/components/fragments/form-message/message-list.js';
import React, { useId } from 'react';
import { CustomizableRadioGroup } from './customizable-radio-group.js';
import { Radio } from './radio.js';
const RadioGroup = React.forwardRef(({ autoFocus, className, defaultValue, description, disabled, warnings = [], errors = [], id: propId, label, name, onChange, options = [], required, value, ...props }, ref) => {
    const hasLabel = label !== undefined;
    const hasError = errors.length > 0;
    const prefix = useId();
    const id = propId ?? `${prefix}-radio-group`;
    return (_jsxs(CustomizableRadioGroup, { "aria-invalid": hasError, "aria-label": !hasLabel ? 'Radio group' : undefined, "aria-required": required, autoFocus: autoFocus, className: cn('flex flex-col gap-2', 'radio-group', className), defaultValue: defaultValue, id: id, name: name, onValueChange: (newValue) => {
            onChange?.(newValue);
        }, value: value, disabled: disabled, ...props, ref: ref, children: [hasLabel && (_jsx(FormLabel, { description: description, hasError: hasError, htmlFor: id, required: required, disabled: disabled, children: label })), options.map((option, index) => (_jsx("div", { className: cn('flex items-center gap-2', 'radio-group__item'), role: "presentation", children: _jsx(Radio, { id: `${prefix}-radio-${index}-${option.value}`, label: option.label, value: option.value, description: option.description, disabled: disabled || option.disabled, hasError: hasError }) }, `${prefix}-radio-${index}-${option.value}`))), warnings.length > 0 && _jsx(FormMessageList, { messages: warnings, type: "warning" }), hasError && _jsx(FormMessageList, { messages: errors, type: "error" })] }));
});
RadioGroup.displayName = 'RadioGroup';
export { RadioGroup };
//# sourceMappingURL=radio-group.js.map