import _extends from '../../../../../@babel_runtime@7.24.8/node_modules/@babel/runtime/helpers/esm/extends.js';
import { forwardRef, createElement, useRef, useEffect, useState } from 'react';
import { composeEventHandlers as $e42e1063c40fb3ef$export$b9ecd428b558ff10 } from '../../../../../@radix-ui_primitive@1.0.1/node_modules/@radix-ui/primitive/dist/index.js';
import { useComposedRefs as $6ed0406888f73fc4$export$c7b2cbe3552a0d05 } from '../../../../../@radix-ui_react-compose-refs@1.0.1_@types_react@18.2.12_react@18.2.0/node_modules/@radix-ui/react-compose-refs/dist/index.js';
import { createContextScope as $c512c27ab02ef895$export$50c7b4e9d9f19c1 } from '../../../../../@radix-ui_react-context@1.0.1_@types_react@18.2.12_react@18.2.0/node_modules/@radix-ui/react-context/dist/index.js';
import { Primitive as $8927f6f2acc4f386$export$250ffa63cdc0d034 } from '../../../../../@radix-ui_react-primitive@1.0.3_@types_react-dom@18.0.11_@types_react@18.2.12_react-dom@18.3._44pjkdrkjq3hxuh62jsxoggm4e/node_modules/@radix-ui/react-primitive/dist/index.js';
import { createRovingFocusGroupScope as $d7bdfb9eb0fdf311$export$c7109489551a4f4, Root as $d7bdfb9eb0fdf311$export$be92b6f5f03c0fe9, Item as $d7bdfb9eb0fdf311$export$6d08773d2e66f8f2 } from '../../../../../@radix-ui_react-roving-focus@1.0.4_@types_react-dom@18.0.11_@types_react@18.2.12_react-dom@18_753i7szl5dwsjermawvfyhbcfq/node_modules/@radix-ui/react-roving-focus/dist/index.js';
import { useControllableState as $71cd76cc60e0454e$export$6f32135080cb4c3 } from '../../../../../@radix-ui_react-use-controllable-state@1.0.1_@types_react@18.2.12_react@18.2.0/node_modules/@radix-ui/react-use-controllable-state/dist/index.js';
import { useDirection as $f631663db3294ace$export$b39126d51d94e6f3 } from '../../../../../@radix-ui_react-direction@1.0.1_@types_react@18.2.12_react@18.2.0/node_modules/@radix-ui/react-direction/dist/index.js';
import { useSize as $db6c3485150b8e66$export$1ab7ae714698c4b8 } from '../../../../../@radix-ui_react-use-size@1.0.1_@types_react@18.2.12_react@18.2.0/node_modules/@radix-ui/react-use-size/dist/index.js';
import { usePrevious as $010c2913dbd2fe3d$export$5cae361ad82dce8b } from '../../../../../@radix-ui_react-use-previous@1.0.1_@types_react@18.2.12_react@18.2.0/node_modules/@radix-ui/react-use-previous/dist/index.js';
import { Presence as $921a889cee6df7e8$export$99c2b779aa4e8b8b } from '../../../../../@radix-ui_react-presence@1.0.1_@types_react-dom@18.0.11_@types_react@18.2.12_react-dom@18.3.1_react@18.2.0__react@18.2.0/node_modules/@radix-ui/react-presence/dist/index.js';

/* -------------------------------------------------------------------------------------------------
 * Radio
 * -----------------------------------------------------------------------------------------------*/ const $ce77a8961b41be9e$var$RADIO_NAME = 'Radio';
const [$ce77a8961b41be9e$var$createRadioContext, $ce77a8961b41be9e$export$67d2296460f1b002] = $c512c27ab02ef895$export$50c7b4e9d9f19c1($ce77a8961b41be9e$var$RADIO_NAME);
const [$ce77a8961b41be9e$var$RadioProvider, $ce77a8961b41be9e$var$useRadioContext] = $ce77a8961b41be9e$var$createRadioContext($ce77a8961b41be9e$var$RADIO_NAME);
const $ce77a8961b41be9e$export$d7b12c4107be0d61 = /*#__PURE__*/ forwardRef((props, forwardedRef)=>{
    const { __scopeRadio: __scopeRadio , name: name , checked: checked = false , required: required , disabled: disabled , value: value = 'on' , onCheck: onCheck , ...radioProps } = props;
    const [button, setButton] = useState(null);
    const composedRefs = $6ed0406888f73fc4$export$c7b2cbe3552a0d05(forwardedRef, (node)=>setButton(node)
    );
    const hasConsumerStoppedPropagationRef = useRef(false); // We set this to true by default so that events bubble to forms without JS (SSR)
    const isFormControl = button ? Boolean(button.closest('form')) : true;
    return /*#__PURE__*/ createElement($ce77a8961b41be9e$var$RadioProvider, {
        scope: __scopeRadio,
        checked: checked,
        disabled: disabled
    }, /*#__PURE__*/ createElement($8927f6f2acc4f386$export$250ffa63cdc0d034.button, _extends({
        type: "button",
        role: "radio",
        "aria-checked": checked,
        "data-state": $ce77a8961b41be9e$var$getState(checked),
        "data-disabled": disabled ? '' : undefined,
        disabled: disabled,
        value: value
    }, radioProps, {
        ref: composedRefs,
        onClick: $e42e1063c40fb3ef$export$b9ecd428b558ff10(props.onClick, (event)=>{
            // radios cannot be unchecked so we only communicate a checked state
            if (!checked) onCheck === null || onCheck === void 0 || onCheck();
            if (isFormControl) {
                hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(); // if radio is in a form, stop propagation from the button so that we only propagate
                // one click event (from the input). We propagate changes from an input so that native
                // form validation works and form events reflect radio updates.
                if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
            }
        })
    })), isFormControl && /*#__PURE__*/ createElement($ce77a8961b41be9e$var$BubbleInput, {
        control: button,
        bubbles: !hasConsumerStoppedPropagationRef.current,
        name: name,
        value: value,
        checked: checked,
        required: required,
        disabled: disabled // We transform because the input is absolutely positioned but we have
        ,
        style: {
            transform: 'translateX(-100%)'
        }
    }));
});
/* -------------------------------------------------------------------------------------------------
 * RadioIndicator
 * -----------------------------------------------------------------------------------------------*/ const $ce77a8961b41be9e$var$INDICATOR_NAME = 'RadioIndicator';
const $ce77a8961b41be9e$export$d35a9ffa9a04f9e7 = /*#__PURE__*/ forwardRef((props, forwardedRef)=>{
    const { __scopeRadio: __scopeRadio , forceMount: forceMount , ...indicatorProps } = props;
    const context = $ce77a8961b41be9e$var$useRadioContext($ce77a8961b41be9e$var$INDICATOR_NAME, __scopeRadio);
    return /*#__PURE__*/ createElement($921a889cee6df7e8$export$99c2b779aa4e8b8b, {
        present: forceMount || context.checked
    }, /*#__PURE__*/ createElement($8927f6f2acc4f386$export$250ffa63cdc0d034.span, _extends({
        "data-state": $ce77a8961b41be9e$var$getState(context.checked),
        "data-disabled": context.disabled ? '' : undefined
    }, indicatorProps, {
        ref: forwardedRef
    })));
});
/* ---------------------------------------------------------------------------------------------- */ const $ce77a8961b41be9e$var$BubbleInput = (props)=>{
    const { control: control , checked: checked , bubbles: bubbles = true , ...inputProps } = props;
    const ref = useRef(null);
    const prevChecked = $010c2913dbd2fe3d$export$5cae361ad82dce8b(checked);
    const controlSize = $db6c3485150b8e66$export$1ab7ae714698c4b8(control); // Bubble checked change to parents (e.g form change event)
    useEffect(()=>{
        const input = ref.current;
        const inputProto = window.HTMLInputElement.prototype;
        const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked');
        const setChecked = descriptor.set;
        if (prevChecked !== checked && setChecked) {
            const event = new Event('click', {
                bubbles: bubbles
            });
            setChecked.call(input, checked);
            input.dispatchEvent(event);
        }
    }, [
        prevChecked,
        checked,
        bubbles
    ]);
    return /*#__PURE__*/ createElement("input", _extends({
        type: "radio",
        "aria-hidden": true,
        defaultChecked: checked
    }, inputProps, {
        tabIndex: -1,
        ref: ref,
        style: {
            ...props.style,
            ...controlSize,
            position: 'absolute',
            pointerEvents: 'none',
            opacity: 0,
            margin: 0
        }
    }));
};
function $ce77a8961b41be9e$var$getState(checked) {
    return checked ? 'checked' : 'unchecked';
}


const $f99a8c78507165f7$var$ARROW_KEYS = [
    'ArrowUp',
    'ArrowDown',
    'ArrowLeft',
    'ArrowRight'
];
/* -------------------------------------------------------------------------------------------------
 * RadioGroup
 * -----------------------------------------------------------------------------------------------*/ const $f99a8c78507165f7$var$RADIO_GROUP_NAME = 'RadioGroup';
const [$f99a8c78507165f7$var$createRadioGroupContext, $f99a8c78507165f7$export$c547093f11b76da2] = $c512c27ab02ef895$export$50c7b4e9d9f19c1($f99a8c78507165f7$var$RADIO_GROUP_NAME, [
    $d7bdfb9eb0fdf311$export$c7109489551a4f4,
    $ce77a8961b41be9e$export$67d2296460f1b002
]);
const $f99a8c78507165f7$var$useRovingFocusGroupScope = $d7bdfb9eb0fdf311$export$c7109489551a4f4();
const $f99a8c78507165f7$var$useRadioScope = $ce77a8961b41be9e$export$67d2296460f1b002();
const [$f99a8c78507165f7$var$RadioGroupProvider, $f99a8c78507165f7$var$useRadioGroupContext] = $f99a8c78507165f7$var$createRadioGroupContext($f99a8c78507165f7$var$RADIO_GROUP_NAME);
const $f99a8c78507165f7$export$a98f0dcb43a68a25 = /*#__PURE__*/ forwardRef((props, forwardedRef)=>{
    const { __scopeRadioGroup: __scopeRadioGroup , name: name , defaultValue: defaultValue , value: valueProp , required: required = false , disabled: disabled = false , orientation: orientation , dir: dir , loop: loop = true , onValueChange: onValueChange , ...groupProps } = props;
    const rovingFocusGroupScope = $f99a8c78507165f7$var$useRovingFocusGroupScope(__scopeRadioGroup);
    const direction = $f631663db3294ace$export$b39126d51d94e6f3(dir);
    const [value, setValue] = $71cd76cc60e0454e$export$6f32135080cb4c3({
        prop: valueProp,
        defaultProp: defaultValue,
        onChange: onValueChange
    });
    return /*#__PURE__*/ createElement($f99a8c78507165f7$var$RadioGroupProvider, {
        scope: __scopeRadioGroup,
        name: name,
        required: required,
        disabled: disabled,
        value: value,
        onValueChange: setValue
    }, /*#__PURE__*/ createElement($d7bdfb9eb0fdf311$export$be92b6f5f03c0fe9, _extends({
        asChild: true
    }, rovingFocusGroupScope, {
        orientation: orientation,
        dir: direction,
        loop: loop
    }), /*#__PURE__*/ createElement($8927f6f2acc4f386$export$250ffa63cdc0d034.div, _extends({
        role: "radiogroup",
        "aria-required": required,
        "aria-orientation": orientation,
        "data-disabled": disabled ? '' : undefined,
        dir: direction
    }, groupProps, {
        ref: forwardedRef
    }))));
});
/* -------------------------------------------------------------------------------------------------
 * RadioGroupItem
 * -----------------------------------------------------------------------------------------------*/ const $f99a8c78507165f7$var$ITEM_NAME = 'RadioGroupItem';
const $f99a8c78507165f7$export$9f866c100ef519e4 = /*#__PURE__*/ forwardRef((props, forwardedRef)=>{
    const { __scopeRadioGroup: __scopeRadioGroup , disabled: disabled , ...itemProps } = props;
    const context = $f99a8c78507165f7$var$useRadioGroupContext($f99a8c78507165f7$var$ITEM_NAME, __scopeRadioGroup);
    const isDisabled = context.disabled || disabled;
    const rovingFocusGroupScope = $f99a8c78507165f7$var$useRovingFocusGroupScope(__scopeRadioGroup);
    const radioScope = $f99a8c78507165f7$var$useRadioScope(__scopeRadioGroup);
    const ref = useRef(null);
    const composedRefs = $6ed0406888f73fc4$export$c7b2cbe3552a0d05(forwardedRef, ref);
    const checked = context.value === itemProps.value;
    const isArrowKeyPressedRef = useRef(false);
    useEffect(()=>{
        const handleKeyDown = (event)=>{
            if ($f99a8c78507165f7$var$ARROW_KEYS.includes(event.key)) isArrowKeyPressedRef.current = true;
        };
        const handleKeyUp = ()=>isArrowKeyPressedRef.current = false
        ;
        document.addEventListener('keydown', handleKeyDown);
        document.addEventListener('keyup', handleKeyUp);
        return ()=>{
            document.removeEventListener('keydown', handleKeyDown);
            document.removeEventListener('keyup', handleKeyUp);
        };
    }, []);
    return /*#__PURE__*/ createElement($d7bdfb9eb0fdf311$export$6d08773d2e66f8f2, _extends({
        asChild: true
    }, rovingFocusGroupScope, {
        focusable: !isDisabled,
        active: checked
    }), /*#__PURE__*/ createElement($ce77a8961b41be9e$export$d7b12c4107be0d61, _extends({
        disabled: isDisabled,
        required: context.required,
        checked: checked
    }, radioScope, itemProps, {
        name: context.name,
        ref: composedRefs,
        onCheck: ()=>context.onValueChange(itemProps.value)
        ,
        onKeyDown: $e42e1063c40fb3ef$export$b9ecd428b558ff10((event)=>{
            // According to WAI ARIA, radio groups don't activate items on enter keypress
            if (event.key === 'Enter') event.preventDefault();
        }),
        onFocus: $e42e1063c40fb3ef$export$b9ecd428b558ff10(itemProps.onFocus, ()=>{
            var _ref$current;
            /**
       * Our `RovingFocusGroup` will focus the radio when navigating with arrow keys
       * and we need to "check" it in that case. We click it to "check" it (instead
       * of updating `context.value`) so that the radio change event fires.
       */ if (isArrowKeyPressedRef.current) (_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.click();
        })
    })));
});
const $f99a8c78507165f7$export$5fb54c671a65c88 = /*#__PURE__*/ forwardRef((props, forwardedRef)=>{
    const { __scopeRadioGroup: __scopeRadioGroup , ...indicatorProps } = props;
    const radioScope = $f99a8c78507165f7$var$useRadioScope(__scopeRadioGroup);
    return /*#__PURE__*/ createElement($ce77a8961b41be9e$export$d35a9ffa9a04f9e7, _extends({}, radioScope, indicatorProps, {
        ref: forwardedRef
    }));
});
/* ---------------------------------------------------------------------------------------------- */ const $f99a8c78507165f7$export$be92b6f5f03c0fe9 = $f99a8c78507165f7$export$a98f0dcb43a68a25;
const $f99a8c78507165f7$export$6d08773d2e66f8f2 = $f99a8c78507165f7$export$9f866c100ef519e4;
const $f99a8c78507165f7$export$adb584737d712b70 = $f99a8c78507165f7$export$5fb54c671a65c88;

export { $f99a8c78507165f7$export$adb584737d712b70 as Indicator, $f99a8c78507165f7$export$6d08773d2e66f8f2 as Item, $f99a8c78507165f7$export$a98f0dcb43a68a25 as RadioGroup, $f99a8c78507165f7$export$5fb54c671a65c88 as RadioGroupIndicator, $f99a8c78507165f7$export$9f866c100ef519e4 as RadioGroupItem, $f99a8c78507165f7$export$be92b6f5f03c0fe9 as Root, $f99a8c78507165f7$export$c547093f11b76da2 as createRadioGroupScope };
//# sourceMappingURL=index.js.map
