import Link from '@/components/LocalizedLink' import { generateSeoMetadata } from '@/lib/seo' import DynamicPageRenderer from '@/components/dynamic/DynamicPageRenderer' import ProductCard from '@/components/ProductCard' import { getCategoriesResult, getCmsPageResult, getProductsResult } from '@/lib/cms' import { splitCmsLayoutSections } from '@/lib/cms-sections' import { resolveLocalized } from '@/lib/localization' export async function generateMetadata({ params }: { params: Promise<{ lang: string }> }) { const { lang } = await params; return generateSeoMetadata({ title: 'Search Products | HomAroma', description: 'Search HomAroma products by scent, category, or keyword.', path: '/search', lang, }); } export default async function SearchPage({ searchParams, params }: { searchParams: Promise<{ q?: string | string[] }>, params: Promise<{ lang: string }> }) { const { lang } = await params const sParams = await searchParams const rawQuery = Array.isArray(sParams.q) ? sParams.q[0] : sParams.q const query = rawQuery?.trim() ?? '' const [categoriesResult, cmsLayoutResult, productsResult] = await Promise.all([ getCategoriesResult(lang), getCmsPageResult('search-layout', lang), query ? getProductsResult(`search=${encodeURIComponent(query)}&limit=1000`, lang) : Promise.resolve({ ok: true as const, data: [] }), ]) const categories = categoriesResult.ok ? categoriesResult.data : [] const cmsSections = cmsLayoutResult.ok ? cmsLayoutResult.data.sections ?? [] : [] const { announcementSections, heroSections, bottomSections } = splitCmsLayoutSections(cmsSections) const products = productsResult.ok ? productsResult.data : [] if (!cmsLayoutResult.ok && cmsLayoutResult.status !== 404) { console.error(`[website-cms] search-layout unavailable: ${cmsLayoutResult.error}`) } return (
Search
{products.length > 0 ? `Found ${products.length} result${products.length !== 1 ? 's' : ''} for "${query}"` : `No results for "${query}"`}
)}Type something to search
Browse All Products →Unable to search products
{productsResult.error}
No products found
Try a different scent name or keyword.
Browse All Products →