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