import { ref as a, watch as i, toValue as S, computed as h } from "vue";
import { createFuseInstance as p } from "../helpers/create-fuse-instance.js";
import { createSearchIndex as x } from "../helpers/create-search-index.js";
const d = 25;
function _(l) {
  const n = p(), e = a();
  i(
    l,
    () => {
      const { entries: r } = S(l), c = x(r);
      n.setCollection(c);
    },
    { immediate: !0 }
  );
  const t = a("");
  i(t, (r) => {
    if (r.length) {
      v();
      return;
    }
    o();
  });
  function o() {
    t.value = "", e.value = void 0, s.value = [];
  }
  const s = a([]), v = () => {
    e.value = 0, s.value = n.search(t.value, {
      limit: d
    });
  }, u = h(() => t.value.length !== 0 ? s.value : n._docs.slice(0, d).map((c, m) => ({
    item: c,
    refIndex: m
  }))), f = h(
    () => typeof e.value == "number" ? u.value[e.value] : void 0
  );
  return {
    resetSearch: o,
    selectedIndex: e,
    selectedSearchResult: f,
    searchResultsWithPlaceholderResults: u,
    query: t
  };
}
export {
  _ as useSearchIndex
};
