import { getAllProducts } from '@/lib/mdx'; import { getTranslations } from 'next-intl/server'; import Image from 'next/image'; import Link from 'next/link'; interface RelatedProductsProps { currentSlug: string; categories: string[]; locale: string; } export default async function RelatedProducts({ currentSlug, categories, locale }: RelatedProductsProps) { const allProducts = await getAllProducts(locale); const t = await getTranslations('Products'); // Filter products: same category, not current product const related = allProducts .filter(p => p.slug !== currentSlug && p.frontmatter.categories.some(cat => categories.includes(cat)) ) .slice(0, 3); // Limit to 3 for better spacing if (related.length === 0) return null; return (

{t('relatedProductsTitle') || 'Related Products'}

{related.map((product) => { // Find the category slug for the link const catSlug = product.frontmatter.categories[0].toLowerCase().replace(/\s+/g, '-'); return (
{product.frontmatter.images?.[0] ? ( <> {product.frontmatter.title}
) : (
No Image
)}
{product.frontmatter.categories.slice(0, 1).map((cat, idx) => ( {cat} ))}

{product.frontmatter.title}

{t('details')}
); })}
); }