import { useCallback, useEffect, useRef, useState } from 'react';
export function useAutoFocusAndSelect({ autoFocus, autoSelect, onFocus, onBlur, localInputRef, value, }) {
    const [isFocused, setIsFocused] = useState(false);
    const autoFocusTriggered = useRef(false);
    const _onFocus = useCallback((event) => {
        setIsFocused(true);
        if (autoSelect) {
            localInputRef.current?.select();
        }
        onFocus?.(event);
    }, [onFocus, localInputRef, autoSelect]);
    const _onBlur = useCallback((event) => {
        setIsFocused(false);
        onBlur?.(event);
    }, [onBlur]);
    useEffect(() => {
        if (autoFocus && !autoFocusTriggered.current && localInputRef.current) {
            localInputRef.current.focus();
            if (autoSelect) {
                localInputRef.current.select();
            }
            else if (value !== undefined) {
                const length = String(value).length;
                localInputRef.current.setSelectionRange(length, length);
            }
            autoFocusTriggered.current = true;
        }
    }, [autoFocus, autoSelect, localInputRef, value]);
    return {
        isFocused,
        _onFocus,
        _onBlur,
    };
}
//# sourceMappingURL=useAutoFocusAndSelect.js.map