import { useState, useEffect } from "react";
const INITIAL_ITEMS = [
  { id: "searxng", name: "Search engine", status: "pending", detail: "" },
  { id: "reranker", name: "ML reranker", status: "pending", detail: "" },
  { id: "embeddings", name: "Embeddings", status: "pending", detail: "" }
];
function createVerifyReporter(setItems, starts) {
  return {
    start(id, _label) {
      starts.set(id, Date.now());
      setItems(
        (prev) => prev.map(
          (item) => item.id === id ? { ...item, status: "checking" } : item
        )
      );
    },
    update() {
    },
    progress() {
    },
    success(id, detail) {
      const elapsed = starts.has(id) ? Date.now() - starts.get(id) : void 0;
      setItems(
        (prev) => prev.map(
          (item) => item.id === id ? { ...item, status: "pass", detail: detail ?? "ok", timeMs: elapsed } : item
        )
      );
    },
    fail(id, error) {
      const elapsed = starts.has(id) ? Date.now() - starts.get(id) : void 0;
      setItems(
        (prev) => prev.map(
          (item) => item.id === id ? { ...item, status: "fail", detail: error, timeMs: elapsed } : item
        )
      );
    },
    note() {
    },
    finish() {
    }
  };
}
function useVerify(dataDir) {
  const [items, setItems] = useState(INITIAL_ITEMS);
  const [done, setDone] = useState(false);
  const [result, setResult] = useState(null);
  useEffect(() => {
    let cancelled = false;
    const starts = /* @__PURE__ */ new Map();
    const reporter = createVerifyReporter(setItems, starts);
    async function run() {
      const { runVerify } = await import("../verify.js");
      const r = await runVerify(dataDir, reporter);
      if (!cancelled) {
        setResult(r);
        setDone(true);
      }
    }
    run().catch(() => {
      if (!cancelled) setDone(true);
    });
    return () => {
      cancelled = true;
    };
  }, [dataDir]);
  return { items, done, result };
}
export {
  useVerify
};
//# sourceMappingURL=useVerify.js.map