'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { createContext, useContext, useId } from 'react';
import { useGDS } from "../hooks/index.js";
import { cn, splitProps } from "../utils/index.js";
import { Checkable } from "./base/Checkable.js";
export function RadioRoot({ size, children: label, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, name: passedName, value, checked: controlledChecked, defaultChecked, onChange, disabled = false, className, ...props }) {
    useGDS();
    const { rootProps, nestedProps } = splitProps(props);
    const groupContext = useContext(RadioGroupContext);
    const name = passedName ?? groupContext?.name;
    return (_jsx(Checkable, { size: size, label: label, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, name: name, value: value, checked: controlledChecked ?? defaultChecked, disabled: disabled, className: cn('gds-radio', className), ...rootProps, renderInput: (renderProps, { inputProps }) => (_jsxs(Checkable.Box, { ...renderProps, className: cn(renderProps.className, 'rounded-full'), children: [_jsx("input", { ...inputProps, type: "radio", checked: controlledChecked, defaultChecked: defaultChecked, onChange: (event) => onChange?.(event.target.checked), ...nestedProps }), _jsx("span", { className: `
              rounded-full bg-(--text-color-form-checked) transition-opacity
              @state-unchecked/checkable:hidden
              @state-disabled/checkable:opacity-disabled
              @prop-size-small/checkable:size-1
              @prop-size-medium/checkable:size-1.5
              @prop-size-large/checkable:size-2
            ` })] })) }));
}
RadioRoot.displayName = 'Radio';
const RadioGroupContext = createContext(null);
export function RadioGroup({ name: passedName, children, ...props }) {
    const uniqueId = useId();
    const name = passedName ?? `gds-radio-${uniqueId}`;
    return (_jsx(RadioGroupContext.Provider, { value: { name }, children: _jsx("div", { "data-name": name, ...props, children: children }) }));
}
RadioGroup.displayName = 'Radio.Group';
export function RadioArea(props) {
    return _jsx(Checkable.Label, { ...props });
}
RadioArea.displayName = 'Radio.Area';
//# sourceMappingURL=Radio.parts.js.map