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