import Grid from 'components/grid'; import ProductGridItems from 'components/layout/product-grid-items'; import { defaultSort, sorting } from 'lib/constants'; import { woocommerce } from 'lib/woocomerce/woocommerce'; export const metadata = { title: 'Search', description: 'Search for products in the store.' }; export default async function SearchPage(props: { searchParams?: Promise<{ [key: string]: string | string[] | undefined }>; }) { const searchParams = await props.searchParams; const { sort, q: searchValue } = searchParams as { [key: string]: string }; const { sortKey, reverse } = sorting.find((item) => item.slug === sort) || defaultSort; const products = await woocommerce.get('products', { search: searchValue, orderby: sortKey }); const resultsText = products.length > 1 ? 'results' : 'result'; return ( <> {searchValue ? (

{products.length === 0 ? 'There are no products that match ' : `Showing ${products.length} ${resultsText} for `} "{searchValue}"

) : null} {products.length > 0 ? ( ) : null} ); }