import { useEffect } from 'react';

const useKeyboardShortcutsDnd = (activeLayerId, handleDragCancel) => {
  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]);
};

export { useKeyboardShortcutsDnd };
