/* @oracle/oraclejet-preact: undefined */
'use strict';

var jsxRuntime = require('preact/jsx-runtime');
var compat = require('preact/compat');
var useComponentTheme = require('./useComponentTheme-082fc8e4.js');
var useFocus = require('./useFocus-1b288fb9.js');
require('./FormContext-9452bd30.js');
var useFormContext = require('./useFormContext-4c3091dc.js');
require('./FormFieldContext-8418dc68.js');
var useFormFieldContext = require('./useFormFieldContext-20f419ef.js');
var useId = require('./useId-6c0eeb27.js');
require('./TabbableModeContext-e99d527e.js');
var useTabbableMode = require('./useTabbableMode-5c8fd9e5.js');
var useInteractionStyle = require('./useInteractionStyle-379ee8fa.js');
var useTranslationBundle = require('./useTranslationBundle-38c0edae.js');
var CheckboxRadioContext = require('./CheckboxRadioContext-3b134bd1.js');
var Check = require('./Check-1a279253.js');
var RadioButtonOff = require('./RadioButtonOff-b28fd2cb.js');
var RadioButtonOn = require('./RadioButtonOn-77b82ecb.js');
var HiddenAccessible = require('./HiddenAccessible-087eb49a.js');
var RadioItemContext = require('./RadioItemContext-3a86c17d.js');


require('./UNSAFE_UserAssistance/themes/redwood/UserAssistanceVariants.css.js');
require('preact/hooks');
require('./Flex-da9f223a.js');


require('./UNSAFE_MessageBanner/themes/redwood/MessageBannerVariants.css.js');
require('preact');
require('./LayerHost-8ec73638.js');


require('./hooks/UNSAFE_useTooltip/themes/redwood/TooltipContentVariants.css.js');
require('./tooltipUtils-d461919d.js');

require('./IconButton-fad4e4b2.js');

require('./MessageFormattingUtils-42d84399.js');
require('./logger-2b636482.js');
require('./TransitionGroup-b239d98f.js');
require('./MessagesContext-4e939750.js');


require('./UNSAFE_ComponentMessage/themes/redwood/ComponentMessageVariants.css.js');
require('./InputGroupContext-05f2a46f.js');
require('./Popup-17440baa.js');
require('./UNSAFE_Separator/themes/SeparatorStyles.css.js');


require('./UNSAFE_Label/themes/redwood/LabelVariants.css.js');
var IconUserAssistance = require('./IconUserAssistance-f247ab50.js');
var UNSAFE_RadioItem_themes_RadioIconContract_css = require('./UNSAFE_RadioItem/themes/RadioIconContract.css.js');
var UNSAFE_RadioItem_themes_redwood_RadioIconTheme = require('./UNSAFE_RadioItem/themes/redwood/RadioIconTheme.js');
var UNSAFE_RadioItem_themes_redwood_RadioTheme = require('./UNSAFE_RadioItem/themes/redwood/RadioTheme.js');

/**
 * RadioItem is an input element of type radio.
 */
const RadioItem = ({ value, children, ...assistanceProps }) => {
    const { isReadonly: isFormReadonly, isDisabled: isFormDisabled } = useFormContext.useFormContext();
    const { isDisabled: isFieldDisabled, isReadonly: isFieldReadonly } = useFormFieldContext.useFormFieldContext();
    const { name, value: groupValue, onCommit } = RadioItemContext.useRadioSetContext();
    const { isFocusRingShown } = CheckboxRadioContext.useCheckboxRadioContext();
    const { index } = RadioItemContext.useRadioItemContext();
    const { isTabbable } = useTabbableMode.useTabbableMode();
    const id = useId.useId();
    const { isFocus, focusProps } = useFocus.useFocus();
    const labelRef = compat.createRef();
    const isSelected = groupValue === value;
    const isDisabled = isFieldDisabled ?? isFormDisabled;
    const isReadonly = isFieldReadonly ?? isFormReadonly;
    const { interactionProps, applyActiveStyle } = useInteractionStyle.useInteractionStyle();
    const { classes: radioClasses, styles: { valueLabelStyle } } = useComponentTheme.useComponentTheme(UNSAFE_RadioItem_themes_redwood_RadioTheme.RadioRedwoodTheme, {
        disabled: isDisabled ? 'isDisabled' : 'notDisabled',
        focused: isFocus && isFocusRingShown ? 'isFocused' : ''
    });
    const { classes: radioIconClasses } = useComponentTheme.useComponentTheme(UNSAFE_RadioItem_themes_redwood_RadioIconTheme.RadioIconRedwoodTheme, {
        disabled: isDisabled ? 'isDisabled' : 'notDisabled',
        selected: isSelected ? 'isSelected' : 'notSelected',
        readonly: isReadonly ? 'isReadonly' : 'notReadonly',
        active: applyActiveStyle ? 'isActive' : 'notActive'
    });
    // JET-70100 - ensure radio button is scrolled into view when focused and focus ring is shown
    compat.useEffect(() => {
        if (isFocus && isFocusRingShown) {
            labelRef?.current?.scrollIntoView({ block: 'nearest' });
        }
    }, [isFocus, isFocusRingShown, labelRef]);
    const { assistiveText, helpSourceLink } = assistanceProps;
    const hasUserAssistive = !isDisabled && !isReadonly && !!(assistiveText || helpSourceLink);
    const helpAvailableId = hasUserAssistive ? `${id}-help-available` : undefined;
    const uaId = hasUserAssistive ? `${id}-icon-ua` : undefined;
    const translations = useTranslationBundle.useTranslationBundle('@oracle/oraclejet-preact');
    const helpAvailableString = translations.formControl_helpAvailable();
    const IconComp = isReadonly
        ? isSelected
            ? Check.SvgCheck
            : RadioButtonOff.SvgRadioButtonOff
        : isSelected
            ? RadioButtonOn.SvgRadioButtonOn
            : RadioButtonOff.SvgRadioButtonOff;
    const tabIndex = isTabbable !== false && ((index === 0 && !groupValue) || isSelected) ? 0 : -1;
    return (jsxRuntime.jsx("div", { children: jsxRuntime.jsxs("label", { class: radioClasses, ref: labelRef, children: [jsxRuntime.jsxs(HiddenAccessible.HiddenAccessible, { children: [jsxRuntime.jsx("input", { type: "radio", name: name, id: id, value: value, ...(!isReadonly &&
                                !isDisabled && {
                                onChange: (e) => {
                                    e.stopPropagation();
                                    onCommit?.({ previousValue: groupValue, value });
                                }
                            }), checked: isSelected, disabled: isDisabled, "aria-describedby": helpAvailableId, tabIndex: tabIndex, ...focusProps }), hasUserAssistive && (jsxRuntime.jsx(HiddenAccessible.HiddenAccessible, { id: helpAvailableId, isHidden: true, children: helpAvailableString }))] }), jsxRuntime.jsx("span", { "aria-hidden": "true", class: radioIconClasses, ...interactionProps, children: jsxRuntime.jsx(IconComp, { size: UNSAFE_RadioItem_themes_RadioIconContract_css.radioIconVars.iconSize, color: "currentColor" }) }), jsxRuntime.jsxs("span", { class: valueLabelStyle, children: [jsxRuntime.jsx("span", { ...interactionProps, children: children }), hasUserAssistive && (jsxRuntime.jsx(IconUserAssistance.IconUserAssistance, { ...assistanceProps, isTabbable: isTabbable && isFocus, id: uaId }))] })] }) }));
};

exports.RadioItem = RadioItem;
//# sourceMappingURL=RadioItem-3cc743ff.js.map
