/** @license MIT | @cube-dev/ui-kit v0.0.0-canary-f1f3d22 | Cube Dev Team */
import { mergeProps as mergeProps$1 } from "../../../utils/react/mergeProps.js";
import { SliderThumbElement } from "./elements.js";
import { useMemo, useRef } from "react";
import { jsx } from "react/jsx-runtime";
import { VisuallyHidden, useHover, useSliderThumb } from "react-aria";

//#region src/components/fields/Slider/SliderThumb.tsx
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);
	return /* @__PURE__ */ jsx(SliderThumbElement, {
		mods: useMemo(() => {
			return {
				hovered: isHovered,
				dragged: isDragging,
				focused: !isDragging && isFocused,
				disabled: isDisabled,
				collapsed: isCollapsed,
				stuck: isStuck
			};
		}, [
			isHovered,
			isCollapsed,
			isStuck,
			isDragging,
			isFocused,
			isDisabled
		]),
		styles,
		tokens,
		...mergeProps$1(thumbProps, hoverProps),
		role: "presentation",
		children: /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("input", {
			ref: inputRef,
			...inputProps
		}) })
	});
}

//#endregion
export { SliderThumb };
//# sourceMappingURL=SliderThumb.js.map