import { jsxs as g, jsx as C } from "react/jsx-runtime";
import { useState as p, useCallback as a, useEffect as E, createContext as v, useContext as h } from "react";
import { Search as k } from "./search.js";
const u = v(null), b = ({
  children: f,
  shortcutKey: o = "k",
  requireModifier: i = !0,
  searchProps: m
}) => {
  const [c, r] = p(!1), w = a(() => r(!0), []), l = a(() => r(!1), []), n = a(() => r((t) => !t), []);
  return E(() => {
    const t = (e) => {
      const d = e.metaKey || e.ctrlKey;
      if (i ? d && e.key.toLowerCase() === o.toLowerCase() : e.key.toLowerCase() === o.toLowerCase()) {
        if (!d) {
          const s = e.target;
          if (s.tagName === "INPUT" || s.tagName === "TEXTAREA" || s.isContentEditable)
            return;
        }
        e.preventDefault(), n();
      }
    };
    return window.addEventListener("keydown", t), () => window.removeEventListener("keydown", t);
  }, [o, i, n]), /* @__PURE__ */ g(u.Provider, { value: { isOpen: c, open: w, close: l, toggle: n }, children: [
    f,
    /* @__PURE__ */ C(k, { ...m, isOpen: c, onClose: l })
  ] });
}, P = () => h(u);
export {
  b as SearchProvider,
  P as useSearch
};
