// @bun
// src/presentation/features/hooks/useRelatedDocs.ts
import { useMemo } from "react";
import { defaultDocRegistry } from "@contractspec/lib.contracts-spec/docs";
"use client";
function useRelatedDocs(key, tags) {
  const docs = useMemo(() => {
    try {
      const allDocs = defaultDocRegistry.list();
      return allDocs.filter(({ block }) => {
        const keyMatch = block.id.toLowerCase().includes(key.toLowerCase()) || block.title.toLowerCase().includes(key.toLowerCase());
        const tagMatch = tags?.some((t) => block.tags?.some((bt) => bt.toLowerCase().includes(t.toLowerCase())));
        return keyMatch || tagMatch;
      }).map(({ block, route }) => ({
        id: block.id,
        title: block.title,
        summary: block.summary,
        route
      }));
    } catch (e) {
      console.error("Failed to fetch related docs:", e);
      return [];
    }
  }, [key, tags]);
  return docs;
}
export {
  useRelatedDocs
};
