/**
 * Trouve-KA — page de résultats de recherche (enveloppe serveur + Suspense)
 * Author: Simon-Pierre Boucher
 * Contact: contact@spboucher.ai
 */

import { Suspense } from "react";
import type { Metadata } from "next";
import { SearchContent } from "./search-content";

interface SearchPageProps {
  searchParams: Promise<Record<string, string | string[] | undefined>>;
}

export async function generateMetadata({
  searchParams,
}: SearchPageProps): Promise<Metadata> {
  const params = await searchParams;
  const q = typeof params.q === "string" ? params.q.trim() : "";
  return { title: q ? q : "Recherche" };
}

export default function SearchPage() {
  return (
    <Suspense
      fallback={
        <div className="mx-auto w-full max-w-3xl flex-1 px-4 py-16">
          <div className="h-10 animate-pulse rounded-ctl bg-line" />
        </div>
      }
    >
      <SearchContent />
    </Suspense>
  );
}
