import { isMacOS as f } from "@scalar/helpers/general/is-mac-os";
const r = {
  Enter: { event: "operation:send:request:hotkey", modifiers: ["default"] },
  b: { event: "ui:toggle:sidebar", modifiers: ["default"] },
  k: { event: "ui:open:command-palette", modifiers: ["default"] },
  l: { event: "ui:focus:address-bar", modifiers: ["default"] }
}, n = {
  web: r,
  modal: {
    ...r,
    Escape: { event: "ui:close:client-modal", modifiers: [] },
    l: { event: "ui:focus:send-button", modifiers: ["default"] }
  },
  desktop: {
    ...r,
    f: { event: "ui:focus:search", modifiers: ["default"] },
    n: { event: "ui:open:command-palette", modifiers: ["default"] },
    t: { event: "tabs:add:tab", modifiers: ["default"] },
    w: { event: "tabs:close:tab", modifiers: ["default"] },
    ArrowLeft: { event: "tabs:navigate:previous", modifiers: ["default", "altKey"] },
    ArrowRight: { event: "tabs:navigate:next", modifiers: ["default", "altKey"] },
    1: { event: "tabs:focus:tab", modifiers: ["default"] },
    2: { event: "tabs:focus:tab", modifiers: ["default"] },
    3: { event: "tabs:focus:tab", modifiers: ["default"] },
    4: { event: "tabs:focus:tab", modifiers: ["default"] },
    5: { event: "tabs:focus:tab", modifiers: ["default"] },
    6: { event: "tabs:focus:tab", modifiers: ["default"] },
    7: { event: "tabs:focus:tab", modifiers: ["default"] },
    8: { event: "tabs:focus:tab", modifiers: ["default"] },
    9: { event: "tabs:focus:tab-last", modifiers: ["default"] }
  }
}, d = /* @__PURE__ */ new Set(["Escape", "ArrowDown", "ArrowUp", "Enter"]), u = (t, a) => a.length > 0 && a.map((e) => e === "default" ? f() ? "metaKey" : "ctrlKey" : e).every((e) => t[e] === !0), l = (t, a) => {
  if (!(t.target instanceof HTMLElement))
    return !1;
  const e = t.target;
  return e.tagName === "INPUT" ? !d.has(a) : e.tagName === "TEXTAREA" || e.contentEditable === "true" || e.hasAttribute("contenteditable");
}, m = (t, a, e) => {
  const i = t.key === " " ? "Space" : t.key, s = n[e][i];
  if (!s)
    return;
  const o = { event: t };
  if (i === "Escape") {
    a.emit(s.event, o, { skipUnpackProxy: !0 });
    return;
  }
  if (u(t, s.modifiers)) {
    a.emit(s.event, o, { skipUnpackProxy: !0 });
    return;
  }
  s.modifiers.length > 0 || l(t, i) || a.emit(s.event, o, { skipUnpackProxy: !0 });
};
export {
  m as handleHotkeys
};
