import { useEffect } from 'react';

const useKeyboardActions = (actions, ref) => {
    useEffect(() => {
        const handleKeyDown = (event) => {
            if (ref?.current) {
                if (!ref.current.contains(document.activeElement)) {
                    return;
                }
            }
            actions.forEach(({ key, action }) => {
                if (event.key === key) {
                    action();
                }
            });
        };
        window.addEventListener('keydown', handleKeyDown);
        return () => {
            window.removeEventListener('keydown', handleKeyDown);
        };
    }, [actions, ref]);
};

export { useKeyboardActions };
//# sourceMappingURL=UseKeyboardActions.js.map
