import { useHotkeys } from "../../../../../node_modules/.pnpm/react-hotkeys-hook@4.6.1_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/react-hotkeys-hook/dist/react-hotkeys-hook.esm.js";
import { useEditorHelpers, usePreviewMode, useSelectedBrickId, useSelectedSectionId } from "../../../../../use-editor.js";
import "react";
import "../../../../../node_modules/.pnpm/@formkit_auto-animate@0.8.2/node_modules/@formkit/auto-animate/index.js";
import { toast as c } from "../../../../../node_modules/.pnpm/react-hot-toast@2.5.2_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/react-hot-toast/dist/index.js";
import { useDraftHelpers, useDraft, useBrick, useDraftUndoManager } from "../../../../../use-page-data.js";
function useEditorHotKeys() {
  const editorHelpers = useEditorHelpers();
  const draftHelpers = useDraftHelpers();
  const draft = useDraft();
  const previewMode = usePreviewMode();
  const selectedBrickId = useSelectedBrickId();
  const selectedSectionId = useSelectedSectionId();
  const selectedBrick = useBrick(selectedBrickId);
  const { undo, redo } = useDraftUndoManager();
  useHotkeys("esc", () => {
    editorHelpers.deselectBrick();
    editorHelpers.setSelectedSectionId();
    editorHelpers.hidePanel();
  });
  useHotkeys("mod+c", () => {
    const sel = window.getSelection();
    if (!sel?.rangeCount) {
      console.debug("mod+c pressed");
    }
  });
  useHotkeys(["backspace", "del"], (e) => {
    if (selectedBrickId) {
      e.preventDefault();
      draftHelpers.deleteBrick(selectedBrickId);
      editorHelpers.deselectBrick(selectedBrickId);
      editorHelpers.hidePanel("inspector");
    }
  });
  useHotkeys("s", (e) => {
    e.preventDefault();
    editorHelpers.togglePanel("settings");
  });
  useHotkeys("l", (e) => {
    e.preventDefault();
    editorHelpers.togglePanel("library");
  });
  useHotkeys("t", (e) => {
    e.preventDefault();
    editorHelpers.togglePanel("theme");
  });
  useHotkeys("p", (e) => {
    e.preventDefault();
    editorHelpers.togglePanel();
  });
  useHotkeys(["mod+z", "ctrl+z"], (e) => {
    e.preventDefault();
    undo();
  });
  useHotkeys(["mod+shift+z", "ctrl+shift+z"], (e) => {
    e.preventDefault();
    redo();
  });
  useHotkeys(
    ["up", "left"],
    (e) => {
      if (selectedBrickId) {
        e.preventDefault();
        const parentBrick = draftHelpers.getParentBrick(selectedBrickId);
        if (parentBrick) {
          const direction = parentBrick.props.direction === "flex-row" ? "ArrowLeft" : "ArrowUp";
          if (direction === e.key) {
            draftHelpers.moveBrick(selectedBrickId, "previous");
          }
        } else if (e.key === "ArrowLeft") {
          draftHelpers.moveBrick(selectedBrickId, "previous");
        }
      } else if (selectedSectionId && e.key === "ArrowUp") {
        e.preventDefault();
        draftHelpers.moveSectionUp(selectedSectionId);
        const element = document.getElementById(selectedSectionId);
        if (element) {
          element.scrollIntoView({ behavior: "smooth", block: "center" });
        }
      }
    },
    {
      enableOnContentEditable: false
    }
  );
  useHotkeys(
    ["down", "right"],
    (e) => {
      if (selectedBrickId) {
        e.preventDefault();
        const parentBrick = draftHelpers.getParentBrick(selectedBrickId);
        if (parentBrick) {
          const direction = parentBrick.props.direction === "flex-row" ? "ArrowRight" : "ArrowDown";
          if (direction === e.key) {
            draftHelpers.moveBrick(selectedBrickId, "next");
          }
        } else if (e.key === "ArrowRight") {
          draftHelpers.moveBrick(selectedBrickId, "next");
        }
      } else if (selectedSectionId && e.key === "ArrowDown") {
        e.preventDefault();
        draftHelpers.moveSectionDown(selectedSectionId);
        const element = document.getElementById(selectedSectionId);
        if (element) {
          element.scrollIntoView({ behavior: "smooth", block: "center" });
        }
      }
    },
    {
      enableOnContentEditable: false
    }
  );
  useHotkeys("mod+d", (e) => {
    e.preventDefault();
    if (selectedBrickId) {
      draftHelpers.duplicateBrick(selectedBrickId);
      c("Brick duplicated", {
        id: "duplicate-brick"
      });
    }
  });
  useHotkeys("mod+j", (e) => {
    e.preventDefault();
    editorHelpers.toggleEditorEnabled();
  });
  useHotkeys("mod+g", (e) => {
    e.preventDefault();
    console.log("Debugging draft:");
    const { page, site } = draft;
    console.log({ page, site });
  });
  useHotkeys(
    "space",
    (e) => {
      const target = e.target;
      if (target.classList.contains("tiptap")) {
        return;
      }
      e.preventDefault();
      e.stopPropagation();
      if (selectedBrick) {
        draftHelpers.updateBrickProps(
          selectedBrick.id,
          {
            grow: !selectedBrick.props.grow
          },
          previewMode === "mobile"
        );
      }
    },
    {
      enableOnContentEditable: true
    }
  );
}
export {
  useEditorHotKeys
};
//# sourceMappingURL=use-editor-hot-keys.js.map
