/**
 * @license MIT
 * author: Cube Dev Team
 * @cube-dev/ui-kit v0.0.0-canary-c015414
 * Released under the MIT license.
 */

import { jsx as _jsx } from "react/jsx-runtime";
import { useMemo, useRef } from 'react';
import { useHover, useSliderThumb, VisuallyHidden, } from 'react-aria';
import { mergeProps } from '../../../utils/react/index.js';
import { SliderThumbElement } from './elements.js';
export function SliderThumb(props) {
    let { state, index, inputRef, isDisabled, styles, tokens } = props;
    const backupRef = useRef(null);
    inputRef = inputRef || backupRef;
    const { thumbProps, inputProps, isDragging, isFocused } = useSliderThumb({
        ...props,
        inputRef,
    }, state);
    const { hoverProps, isHovered } = useHover({ isDisabled });
    const isCollapsed = state.values[0] === state.values[1];
    const isStuck = state.values[index] === state.getThumbMaxValue(index) &&
        state.values[index] === state.getThumbMinValue(index);
    const mods = useMemo(() => {
        return {
            hovered: isHovered,
            dragged: isDragging,
            focused: !isDragging && isFocused,
            disabled: isDisabled,
            collapsed: isCollapsed,
            stuck: isStuck,
        };
    }, [isHovered, isCollapsed, isStuck, isDragging, isFocused, isDisabled]);
    return (_jsx(SliderThumbElement, { mods: mods, styles: styles, tokens: tokens, ...mergeProps(thumbProps, hoverProps), role: "presentation", children: _jsx(VisuallyHidden, { children: _jsx("input", { ref: inputRef, ...inputProps }) }) }));
}

        