import { Metadata } from "next" import { notFound } from "next/navigation" import { listProducts } from "@lib/data/products" import { getRegion } from "@lib/data/regions" import ProductPreview from "@modules/products/components/product-preview" import SearchForm from "@modules/search/components/search-form" const RESULT_LIMIT = 24 type Props = { params: Promise<{ countryCode: string }> searchParams: Promise<{ q?: string | string[] }> } const getQuery = (q?: string | string[]) => (Array.isArray(q) ? q[0] : q)?.trim().slice(0, 200) ?? "" export async function generateMetadata(props: Props): Promise { const query = getQuery((await props.searchParams).q) return { title: query ? `Search results for "${query}"` : "Search", robots: { index: false, follow: true }, } } export default async function SearchPage(props: Props) { const { countryCode } = await props.params const query = getQuery((await props.searchParams).q) const region = await getRegion(countryCode) if (!region) { notFound() } const { response } = query ? await listProducts({ countryCode, queryParams: { q: query, limit: RESULT_LIMIT }, }) : { response: { products: [], count: 0 } } return (

{query ? `Search results for "${query}"` : "Search"}

{query && (

{response.count} {response.count === 1 ? "product" : "products"} found

)} {query && response.products.length === 0 ? (

No products match your search. Try a different keyword.

) : (
    {response.products.map((product) => (
  • ))}
)}
) }