import { defineComponent as S, ref as b, watch as w, nextTick as v, onMounted as K, onBeforeUnmount as g, createElementBlock as a, openBlock as n, Fragment as r, createElementVNode as s, createVNode as p, normalizeClass as C, unref as l, createTextVNode as u, toDisplayString as M } from "vue";
import { useModal as B } from "@scalar/components";
import { ScalarIconMagnifyingGlass as E } from "@scalar/icons";
import H from "./SearchModal.vue.js";
import { isMacOs as m } from "../../helpers/isMacOs.js";
import { useApiClient as L } from "../ApiClientModal/useApiClient.js";
const N = { class: "sidebar-search-input" }, T = { class: "sidebar-search-shortcut" }, V = { class: "sidebar-search-key" }, G = /* @__PURE__ */ S({
  __name: "SearchButton",
  props: {
    spec: {},
    searchHotKey: { default: "k" }
  },
  setup(f) {
    const h = f, i = b(), t = B(), { client: y } = L(), d = (o) => {
      var e;
      (m() ? o.metaKey : o.ctrlKey) && o.key === h.searchHotKey && !((e = y.value) != null && e.modalState.open) && (o.preventDefault(), o.stopPropagation(), t.open ? t.hide() : t.show());
    };
    w(
      () => t.open,
      (o, e) => {
        !o && e && v(() => {
          var c;
          (c = i.value) == null || c.focus();
        });
      }
    ), K(() => window.addEventListener("keydown", d)), g(() => window.removeEventListener("keydown", d));
    function k() {
      t.show();
    }
    return (o, e) => (n(), a(r, null, [
      s("button", {
        ref_key: "button",
        ref: i,
        class: C(["sidebar-search", o.$attrs.class]),
        role: "search",
        type: "button",
        onClick: k
      }, [
        p(l(E), {
          class: "scalar-search-icon",
          weight: "bold"
        }),
        s("div", N, [
          e[3] || (e[3] = s("span", { class: "sr-only" }, "Open Search", -1)),
          e[4] || (e[4] = s("span", {
            "aria-hidden": "true",
            class: "sidebar-search-placeholder"
          }, " Search ", -1)),
          s("span", T, [
            e[2] || (e[2] = s("span", { class: "sr-only" }, "Keyboard Shortcut:", -1)),
            s("kbd", V, [
              l(m)() ? (n(), a(r, { key: 0 }, [
                u("⌘")
              ], 64)) : (n(), a(r, { key: 1 }, [
                e[0] || (e[0] = s("span", { class: "sr-only" }, "CTRL", -1)),
                e[1] || (e[1] = s("span", { "aria-hidden": "true" }, "⌃", -1))
              ], 64)),
              u(" " + M(o.searchHotKey), 1)
            ])
          ])
        ])
      ], 2),
      p(H, {
        modalState: l(t),
        parsedSpec: o.spec
      }, null, 8, ["modalState", "parsedSpec"])
    ], 64));
  }
});
export {
  G as default
};
