import type { Metadata } from "next"; import Link from "next/link"; import { Container } from "@/components/Container"; import { ProductCard } from "@/components/ui/ProductCard"; import { fetchStoreItems, variantToProduct } from "@/lib/store"; import { getNavCategories } from "@/lib/categories"; import { faDigits } from "@/lib/format"; export const revalidate = 60; export const metadata: Metadata = { title: "محصولات | داروخانه دکتر ارجمند", }; export default async function ProductsPage({ searchParams, }: { searchParams: Promise<{ page?: string; categoryId?: string; q?: string }>; }) { const params = await searchParams; const page = Math.max(1, Number(params.page) || 1); const categoryId = params.categoryId; const q = params.q?.trim(); const [result, nav] = await Promise.all([ fetchStoreItems({ page, pageSize: 20, categoryId, name: q && q.length > 2 ? q : undefined }), getNavCategories(), ]); const products = result.items.map(variantToProduct); const pageCount = Math.max(1, Math.ceil((result.total || products.length) / (result.pageSize || 20))); const categoryTitle = nav .flatMap((item) => [item, ...item.children.map((child) => ({ ...child, children: [] }))]) .find((item) => item.id === categoryId)?.title; return (

خانه / محصولات

{categoryTitle || (q ? `جستجو: ${q}` : "همه محصولات")}

{result.total ? (

{faDigits(result.total)} کالا

) : null}
{products.length === 0 ? (

محصولی برای نمایش وجود ندارد

به‌زودی موجودی فروشگاه از پنل Meshkee اینجا دیده می‌شود.

) : (
{products.map((product) => ( ))}
)} {pageCount > 1 ? (
{Array.from({ length: pageCount }, (_, index) => { const number = index + 1; const query = new URLSearchParams(); if (categoryId) query.set("categoryId", categoryId); if (q) query.set("q", q); query.set("page", String(number)); return ( {faDigits(number)} ); })}
) : null}
); }