import "server-only";

import type { Dictionary } from "@/app/[lang]/dictionaries";
import {
  buildDocsSearchIndex,
  type DocsSearchRecord,
} from "@/lib/docs/search-index";
import { buildSiteIndex } from "@/lib/search/site-index";

/**
 * Combined search index for marketing surfaces: curated site records plus the
 * docs index, filtered to the active locale. Shared by the marketing layout
 * (navbar search) and the blog hero search so the two never drift.
 * `buildDocsSearchIndex` is request-memoised (React `cache()`), so calling this
 * from both the layout and a page scans the docs files only once per request.
 */
export function buildMarketingSearchIndex(
  dict: Dictionary,
  lang: string,
): DocsSearchRecord[] {
  return [
    ...buildSiteIndex(dict, lang),
    ...buildDocsSearchIndex().filter((r) => r.lang === lang),
  ];
}
