import i, { useContext as p, useCallback as l } from "react";
import { am as C, hS as S, i1 as D, H as d, iX as f, iY as E, cd as k, iZ as m, il as x, i_ as b, i$ as N } from "./56c67d3b.js";
import { c as g } from "./99912daf.js";
import { g as w } from "./70d94dee.js";
import "react-dom";
function v(t, e, s, o, a, r) {
  switch (w(t, "global")) {
    case "toggleLeftPanel":
      o("left");
      break;
    case "toggleBottomPanel":
      o("bottom");
      break;
    case "toggleRightPanel":
      o("right");
      break;
    case "toggleAllPanels":
      o();
      break;
    case "preview":
      x(r);
      break;
    case "undo":
      s == null || s.undo();
      break;
    case "redo":
      s == null || s.redo();
      break;
    case "deleteComps":
      m.deleteComp(e, e.selectedComps());
      return;
    case "toggleShortcutList":
      a();
      return;
    case "executeQuery": {
      const n = e.selectedQueryComp();
      n == null || n.dispatch(k({
        afterExecFunc: () => e.setShowResultCompName(n.children.name.getView())
      }));
      break;
    }
    default:
      return;
  }
  t.stopPropagation(), t.preventDefault();
}
function u(t, e) {
  t.setForceShowGrid(e ? b(e) : !1), t.setDisableInteract(e ? N(e) : !1);
}
function A(t, e, s) {
  if (!b(t))
    return;
  const o = t.target || t.srcElement;
  if (!o)
    return;
  if (o.className !== g) {
    const n = o.parentElement;
    if (!n || n.className !== g)
      return;
  }
  s();
  const a = o.innerText;
  if (e.getUICompByName(a)) {
    e.setSelectedCompNames(/* @__PURE__ */ new Set([a]));
    return;
  }
  const r = e.getBottomResComp(a);
  if (r) {
    e.setSelectedBottomRes(a, r.type());
    return;
  }
}
const L = i.memo((t) => {
  const e = p(C), {
    history: s
  } = p(S), {
    togglePanel: o,
    panelStatus: a,
    toggleShortcutList: r
  } = t, n = D(), y = l((c) => {
    u(e, c), v(c, e, s, o, r, n), e.getAppSettingsComp().children.customShortcuts.handleKeyEvent(c);
  }, [e, s, o, r, n]), h = l((c) => u(e, c), [e]), K = l((c) => {
    u(e, c), A(c, e, () => !a.left && o("left"));
  }, [e, a, o]);
  return /* @__PURE__ */ d(f, {
    disabled: t.disabled,
    onKeyDownCapture: y,
    onKeyUpCapture: h,
    onMouseMoveCapture: h,
    onMouseDownCapture: K,
    children: t.children
  });
});
function G(t, e) {
  switch (w(t, "editor")) {
    case "selectAllComps":
      e.setSelectedCompNames(new Set(Object.values(e.getUIComp().getTopCompItems()).map((s) => s.children.name.getView()))), t.preventDefault(), t.stopPropagation();
      return;
    case "copyComps":
      m.copyComp(e, e.selectedComps());
      return;
    case "pasteComps":
      m.pasteComp(e);
      return;
    case "cutComps":
      m.cutComp(e, e.selectedComps());
      return;
    case "deselectComps":
      e.setSelectedCompNames(/* @__PURE__ */ new Set());
      return;
  }
}
const Q = i.memo((t) => {
  const e = p(C), s = l((o) => G(o, e), [e]);
  return /* @__PURE__ */ d(E, {
    disabled: t.disabled,
    onKeyDown: s,
    style: {
      width: "100%",
      height: "100%"
    },
    children: t.children
  });
}), U = i.memo((t) => {
  const e = p(C), s = l((o) => {
    e.getAppSettingsComp().children.customShortcuts.handleKeyEvent(o);
  }, [e]);
  return /* @__PURE__ */ d(f, {
    onKeyDownCapture: s,
    children: t.children
  });
});
export {
  U as CustomShortcutWrapper,
  L as EditorGlobalHotKeys,
  Q as EditorHotKeys
};
