"use client";
import { DEFAULT_LTR_KEYBOARD_MOVEMENT_WITHOUT_JUMP, DEFAULT_RTL_KEYBOARD_MOVEMENT_WITHOUT_JUMP } from "../movement/constants.js";
import { useKeyboardMovementProvider } from "../movement/useKeyboardMovementProvider.js";
import { useDir } from "../typography/WritingDirectionProvider.js";
const SPINBUTTON_ROLE = '[role="spinbutton"]';
/**
 * @internal
 * @since 6.4.0
 */ const getSpinButtonsOnly = (container)=>[
        ...container.querySelectorAll(SPINBUTTON_ROLE)
    ];
/**
 * @since 6.4.0
 */ export function useSpinButtonGroupProvider(options = {}) {
    const { disabled, forceFocusWithin } = options;
    const isRTL = useDir().dir === "rtl";
    const movementKeys = isRTL ? DEFAULT_RTL_KEYBOARD_MOVEMENT_WITHOUT_JUMP : DEFAULT_LTR_KEYBOARD_MOVEMENT_WITHOUT_JUMP;
    const { movementProps, ...remaining } = useKeyboardMovementProvider({
        ...options,
        ...movementKeys,
        loopable: false,
        trackTabKeys: true,
        getFocusableElements: getSpinButtonsOnly
    });
    return {
        ...remaining,
        movementProps: {
            ...movementProps,
            role: "group",
            onClick: (event)=>{
                movementProps.onClick(event);
                const { target, currentTarget } = event;
                if (disabled || !forceFocusWithin || !(target instanceof HTMLElement) || target.closest(SPINBUTTON_ROLE)) {
                    return;
                }
                const buttons = [
                    ...currentTarget.querySelectorAll(SPINBUTTON_ROLE)
                ];
                const i = buttons.findIndex((button)=>!button.ariaValueNow);
                remaining.movementContext.updateFocusIndex({
                    index: Math.max(0, i),
                    force: true
                });
            }
        }
    };
}

//# sourceMappingURL=useSpinButtonGroupProvider.js.map