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