'use strict';

const React = require('react');

const useKeyboardShortcutsDnd = (activeLayerId, handleDragCancel) => {
  React.useEffect(() => {
    const handleKeyDown = (event) => {
      if (event.key === "Escape" && activeLayerId) {
        event.preventDefault();
        event.stopPropagation();
        handleDragCancel();
      }
    };
    if (activeLayerId) {
      document.addEventListener("keydown", handleKeyDown);
      return () => {
        document.removeEventListener("keydown", handleKeyDown);
      };
    }
  }, [activeLayerId, handleDragCancel]);
};

exports.useKeyboardShortcutsDnd = useKeyboardShortcutsDnd;
