import { useContext as m, useCallback as l } from "react";
import { bg as i, Z as K, h$ as D, V as C, i0 as g, i1 as S, bJ as E, i2 as p, i3 as k, i4 as f, i5 as x } from "./684d2f28.js";
import { c as h } from "./6478e58a.js";
import { g as b } from "./7069fe87.js";
import "react-dom";
function N(t, e, s, o, a, r) {
  switch (b(t, "global")) {
    case "toggleLeftPanel":
      o("left");
      break;
    case "toggleBottomPanel":
      o("bottom");
      break;
    case "toggleRightPanel":
      o("right");
      break;
    case "toggleAllPanels":
      o();
      break;
    case "preview":
      k(r);
      break;
    case "undo":
      s == null || s.undo();
      break;
    case "redo":
      s == null || s.redo();
      break;
    case "deleteComps":
      p.deleteComp(e, e.selectedComps());
      return;
    case "toggleShortcutList":
      a();
      return;
    case "executeQuery": {
      const n = e.selectedQueryComp();
      n == null || n.dispatch(E({
        afterExecFunc: () => e.setShowResultCompName(n.children.name.getView())
      }));
      break;
    }
    default:
      return;
  }
  t.stopPropagation(), t.preventDefault();
}
function u(t, e) {
  t.setForceShowGrid(e ? f(e) : !1), t.setDisableInteract(e ? x(e) : !1);
}
function v(t, e, s) {
  if (!f(t))
    return;
  const o = t.target || t.srcElement;
  if (!o)
    return;
  if (o.className !== h) {
    const n = o.parentElement;
    if (!n || n.className !== h)
      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;
  }
}
function B(t) {
  const e = m(i), {
    history: s
  } = m(K), {
    togglePanel: o,
    panelStatus: a,
    toggleShortcutList: r
  } = t, n = D(), w = l((c) => {
    u(e, c), N(c, e, s, o, r, n), e.getAppSettingsComp().children.customShortcuts.handleKeyEvent(c);
  }, [e, s, o, r, n]), d = l((c) => u(e, c), [e]), y = l((c) => {
    u(e, c), v(c, e, () => !a.left && o("left"));
  }, [e, a, o]);
  return /* @__PURE__ */ C(g, {
    disabled: t.disabled,
    onKeyDownCapture: w,
    onKeyUpCapture: d,
    onMouseMoveCapture: d,
    onMouseDownCapture: y,
    children: t.children
  });
}
function A(t, e) {
  switch (b(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":
      p.copyComp(e, e.selectedComps());
      return;
    case "pasteComps":
      p.pasteComp(e);
      return;
    case "cutComps":
      p.cutComp(e, e.selectedComps());
      return;
    case "deselectComps":
      e.setSelectedCompNames(/* @__PURE__ */ new Set());
      return;
  }
}
function L(t) {
  const e = m(i), s = l((o) => A(o, e), [e]);
  return /* @__PURE__ */ C(S, {
    disabled: t.disabled,
    onKeyDown: s,
    style: {
      width: "100%",
      height: "100%"
    },
    children: t.children
  });
}
function Q(t) {
  const e = m(i), s = l((o) => {
    e.getAppSettingsComp().children.customShortcuts.handleKeyEvent(o);
  }, [e]);
  return /* @__PURE__ */ C(g, {
    onKeyDownCapture: s,
    children: t.children
  });
}
export {
  Q as CustomShortcutWrapper,
  B as EditorGlobalHotKeys,
  L as EditorHotKeys
};
