'use strict';

const React = require('react');

function useKeyboardShortcuts(combinations) {
  React.useEffect(() => {
    const handleKeyDown = (event) => {
      combinations.forEach((combo) => {
        const { keys: { ctrlKey, metaKey, shiftKey, altKey }, key, handler } = combo;
        const isMatch = (ctrlKey === void 0 || event.ctrlKey === ctrlKey) && (metaKey === void 0 || event.metaKey === metaKey) && (shiftKey === void 0 || event.shiftKey === shiftKey) && (altKey === void 0 || event.altKey === altKey) && event.key.toLowerCase() === key.toLowerCase();
        if (isMatch) {
          event.preventDefault();
          handler(event);
        }
      });
    };
    window.addEventListener("keydown", handleKeyDown);
    return () => {
      window.removeEventListener("keydown", handleKeyDown);
    };
  }, [combinations]);
}

exports.useKeyboardShortcuts = useKeyboardShortcuts;
