/* @oracle/oraclejet-preact: undefined */
import { useRef } from 'preact/hooks';
import { h as handleInput } from './useKeyboardEvents-2378a650.js';
import { u as useDatatip } from './useDatatip-9635bc2f.js';

function usePointerEvents(value, getValue, targetRef, currentInputRef, isPointerActiveRef, onCommit, onInput) {
    const isPointerDown = useRef(false);
    const onPointerUp = (event) => {
        isPointerDown.current = false;
        const val = getValue(event);
        if (val !== undefined) {
            onCommit?.({ value: val });
        }
        isPointerActiveRef.current = true;
    };
    const onPointerMove = (event) => {
        if (isPointerDown.current) {
            const val = getValue(event);
            if (val !== undefined && val != currentInputRef.current) {
                handleInput(val, currentInputRef, onInput);
            }
        }
        isPointerActiveRef.current = true;
    };
    const onPointerDown = (event) => {
        isPointerDown.current = true;
        targetRef.current?.setPointerCapture(event.pointerId);
        const val = getValue(event);
        if (val !== undefined && val != currentInputRef.current) {
            handleInput(val, currentInputRef, onInput);
        }
        isPointerActiveRef.current = true;
    };
    const onBlur = () => {
        isPointerDown.current = false;
        onCommit?.({ value: value });
        isPointerActiveRef.current = false;
    };
    const onPointerLeave = () => {
        isPointerActiveRef.current = false;
    };
    const onPointerEnter = () => {
        isPointerActiveRef.current = true;
    };
    return {
        onPointerUp,
        onBlur,
        onPointerMove,
        onPointerDown,
        onPointerLeave,
        onPointerEnter
    };
}

function useMeterDatatip(value, isPointerActiveRef, datatip, ariaDescribedBy) {
    const datatipText = datatip === undefined ? `${value}` : datatip;
    const { datatipContent, datatipProps } = useDatatip({
        content: datatipText,
        anchor: isPointerActiveRef.current ? 'pointer' : 'element',
        offset: {
            mainAxis: 8,
            crossAxis: 0
        },
        placement: 'top',
        touchResponse: 'touchStart'
    });
    datatipProps['aria-describedby'] =
        [ariaDescribedBy, datatipProps['aria-describedby']].filter(Boolean).join(' ') || undefined;
    return { datatipContent, datatipProps };
}

export { useMeterDatatip as a, usePointerEvents as u };
//# sourceMappingURL=useMeterDatatip-834e67e1.js.map
