import { useState, useEffect } from 'react';
import { useWindowKeyPress } from './useWindowKeyPress.js';

function useHasFocus(ref) {
    const [hasFocus, setHasFocus] = useState(false);
    const tabPressed = useWindowKeyPress('Tab');
    useEffect(() => {
        if (ref.current === document.activeElement) {
            setHasFocus(true);
        }
        else {
            setHasFocus(false);
        }
    }, [tabPressed]);
    return { hasFocus, setHasFocus };
}

export { useHasFocus };
