import type { Metadata } from "next"; import Link from "next/link"; import { Container } from "@/components/Container"; import { PageHero } from "@/components/layout/PageHero"; import { ProductCard } from "@/components/ui/ProductCard"; import { getNavCategories } from "@/lib/categories"; import { faDigits } from "@/lib/format"; import { catalogProductToCard, fetchCatalogProducts, fetchStoreItems, variantToProduct, } from "@/lib/store"; export const revalidate = 60; export const metadata: Metadata = { title: "محصولات", description: "قطعات و لوازم خانگی فروشگاه برادران برقعی", }; 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 name = q && q.length > 2 ? q : undefined; const [storeResult, catalogResult, nav] = await Promise.all([ fetchStoreItems({ page, pageSize: 20, categoryId, name }), fetchCatalogProducts({ page, pageSize: 20, categoryId, name }), getNavCategories(), ]); const fromStore = storeResult.items.map(variantToProduct); const products = fromStore.length ? fromStore : catalogResult.items.map(catalogProductToCard); const total = fromStore.length ? storeResult.total : catalogResult.total; const pageSize = fromStore.length ? storeResult.pageSize : catalogResult.pageSize; const pageCount = Math.max(1, Math.ceil((total || products.length) / (pageSize || 20))); const categoryTitle = nav .flatMap((item) => [item, ...item.children.map((child) => ({ ...child, children: [] as never[] }))]) .find((item) => item.id === categoryId)?.title; const heroTitle = categoryTitle || (q ? `جستجو: ${q}` : "محصولات"); return ( <>
{total ?

{faDigits(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}
); }