import JsonLd from '@/components/JsonLd'; import { SITE_URL } from '@/lib/schema'; import ProductSidebar from '@/components/ProductSidebar'; import ProductTabs from '@/components/ProductTabs'; import ProductTechnicalData from '@/components/ProductTechnicalData'; import RelatedProducts from '@/components/RelatedProducts'; import DatasheetDownload from '@/components/DatasheetDownload'; import { Badge, Card, Container, Heading, Section } from '@/components/ui'; import { getDatasheetPath } from '@/lib/datasheets'; import { getAllProducts, getProductBySlug } from '@/lib/mdx'; import { mapFileSlugToTranslated, mapSlugToFileSlug } from '@/lib/slugs'; import { Metadata } from 'next'; import { getTranslations, setRequestLocale } from 'next-intl/server'; import { getProductOGImageMetadata } from '@/lib/metadata'; import { MDXRemote } from 'next-mdx-remote/rsc'; import Image from 'next/image'; import Link from 'next/link'; import { notFound } from 'next/navigation'; import ProductEngagementTracker from '@/components/analytics/ProductEngagementTracker'; interface ProductPageProps { params: Promise<{ locale: string; slug: string[]; }>; } export async function generateMetadata({ params }: ProductPageProps): Promise { const { locale, slug } = await params; const productSlug = slug[slug.length - 1]; const t = await getTranslations('Products'); // Check if it's a category page const categories = [ 'low-voltage-cables', 'medium-voltage-cables', 'high-voltage-cables', 'solar-cables', ]; const fileSlug = await mapSlugToFileSlug(productSlug, locale); if (categories.includes(fileSlug)) { const categoryKey = fileSlug .replace(/-cables$/, '') .replace(/-([a-z])/g, (g) => g[1].toUpperCase()); const categoryTitle = t.has(`categories.${categoryKey}.title`) ? t(`categories.${categoryKey}.title`) : fileSlug; const categoryDesc = t.has(`categories.${categoryKey}.description`) ? t(`categories.${categoryKey}.description`) : ''; return { title: categoryTitle, description: categoryDesc, alternates: { canonical: `${SITE_URL}/${locale}/products/${productSlug}`, languages: { de: `${SITE_URL}/de/products/${await mapFileSlugToTranslated(productSlug, 'de')}`, en: `${SITE_URL}/en/products/${await mapFileSlugToTranslated(productSlug, 'en')}`, 'x-default': `${SITE_URL}/en/products/${await mapFileSlugToTranslated(productSlug, 'en')}`, }, }, openGraph: { title: `${categoryTitle} | KLZ Cables`, description: categoryDesc, url: `${SITE_URL}/${locale}/products/${productSlug}`, images: getProductOGImageMetadata(fileSlug, categoryTitle, locale), }, twitter: { card: 'summary_large_image', title: `${categoryTitle} | KLZ Cables`, description: categoryDesc, }, }; } const product = await getProductBySlug(productSlug, locale); if (!product) return {}; return { title: product.frontmatter.title, description: product.frontmatter.description, alternates: { canonical: `${SITE_URL}/${locale}/products/${slug.join('/')}`, languages: { de: `${SITE_URL}/de/products/${await mapFileSlugToTranslated(slug[0], 'de')}/${await mapFileSlugToTranslated(productSlug, 'de')}`, en: `${SITE_URL}/en/products/${await mapFileSlugToTranslated(slug[0], 'en')}/${await mapFileSlugToTranslated(productSlug, 'en')}`, 'x-default': `${SITE_URL}/en/products/${await mapFileSlugToTranslated(slug[0], 'en')}/${await mapFileSlugToTranslated(productSlug, 'en')}`, }, }, openGraph: { title: `${product.frontmatter.title} | KLZ Cables`, description: product.frontmatter.description, type: 'website', url: `${SITE_URL}/${locale}/products/${slug.join('/')}`, images: getProductOGImageMetadata(productSlug, product.frontmatter.title, locale), }, twitter: { card: 'summary_large_image', title: `${product.frontmatter.title} | KLZ Cables`, description: product.frontmatter.description, }, }; } const components = { ProductTechnicalData, ProductTabs, p: (props: any) => (

), h1: (props: any) => (

), h2: (props: any) => (

), h3: (props: any) => (

), ul: (props: any) =>
    , section: (props: any) =>
    , li: (props: any) => (
  • ), strong: (props: any) => , table: (props: any) => (
    ), th: (props: any) => (
    ), td: (props: any) => ( ), hr: () =>
    , blockquote: (props: any) => (
    ), }; export default async function ProductPage({ params }: ProductPageProps) { const { locale, slug } = await params; setRequestLocale(locale); const productSlug = slug[slug.length - 1]; const t = await getTranslations('Products'); // Check if it's a category page const categories = [ 'low-voltage-cables', 'medium-voltage-cables', 'high-voltage-cables', 'solar-cables', ]; const fileSlug = await mapSlugToFileSlug(productSlug, locale); if (categories.includes(fileSlug)) { const allProducts = await getAllProducts(locale); const categoryKey = fileSlug .replace(/-cables$/, '') .replace(/-([a-z])/g, (g) => g[1].toUpperCase()); const categoryTitle = t.has(`categories.${categoryKey}.title`) ? t(`categories.${categoryKey}.title`) : fileSlug; // Filter products for this category const filteredProducts = allProducts.filter((p) => p.frontmatter.categories.some( (cat) => cat.toLowerCase().replace(/\s+/g, '-') === fileSlug || cat === categoryTitle, ), ); // Get translated product slugs const productsWithTranslatedSlugs = await Promise.all( filteredProducts.map(async (p) => ({ ...p, translatedSlug: await mapFileSlugToTranslated(p.slug, locale), })), ); return (
    {categoryTitle}
    {productsWithTranslatedSlugs.map((product) => (
    {product.frontmatter.images?.[0] && ( <> {product.frontmatter.title} {/* Subtle reflection/shadow effect */}
    )}
    {product.frontmatter.categories.map((cat, i) => ( {cat} ))}

    {product.frontmatter.title}

    {product.frontmatter.description}

    {t('details')}
    ))}
    ); } const product = await getProductBySlug(productSlug, locale); if (!product) { notFound(); } // Extract technical data for schema const technicalDataMatch = product.content.match( /technicalData=\{\}/s, ); let technicalItems = []; if (technicalDataMatch) { try { const data = JSON.parse(technicalDataMatch[1]); technicalItems = data.technicalItems || []; } catch (e) { console.error('Failed to parse technical data for schema', e); } } const datasheetPath = getDatasheetPath(productSlug, locale); const isFallback = (product.frontmatter as any).isFallback; const categorySlug = slug[0]; const categoryFileSlug = await mapSlugToFileSlug(categorySlug, locale); const categoryKey = categoryFileSlug .replace(/-cables$/, '') .replace(/-([a-z])/g, (g) => g[1].toUpperCase()); const categoryTitle = t.has(`categories.${categoryKey}.title`) ? t(`categories.${categoryKey}.title`) : categoryFileSlug; const sidebar = ( ); const productComponents = { ...components, ProductTabs: (props: any) => , }; // Pre-process content to convert raw HTML tags to Markdown so they use our custom components const processedContent = product.content .replace(/]*>(.*?)<\/h1>/gs, '\n# $1\n') // Maps to our custom h1 (which renders h2) .replace(/]*>(.*?)<\/h2>/gs, '\n## $1\n') // Maps to our custom h2 (which renders h3) .replace(/]*>(.*?)<\/h3>/gs, '\n### $1\n') // Maps to our custom h3 (which renders h4) .replace(/]*>(.*?)<\/p>/gs, '\n$1\n') .replace(/]*>(.*?)<\/ul>/gs, '\n$1\n') .replace(/]*>(.*?)<\/li>/gs, '\n- $1\n') .replace(/]*>(.*?)<\/strong>/gs, '**$1**') .replace(/]*>/gs, '') .replace(/<\/section>/gs, ''); return (
    {/* Product Hero */}
    {/* Background Decorative Elements */}
    {isFallback && (
    {t('englishVersion')}
    )}
    {product.frontmatter.categories.map((cat, idx) => ( {cat} ))}
    {product.frontmatter.title}

    {product.frontmatter.description}

    {/* Large Product Image Section */} {product.frontmatter.images && product.frontmatter.images.length > 0 && (
    {product.frontmatter.title} {/* Subtle reflection/shadow effect */}
    {product.frontmatter.images.length > 1 && (
    {product.frontmatter.images.slice(0, 5).map((img, idx) => (
    ))}
    )}
    )}
    {/* Main Content Area */}
    {/* Datasheet Download Section - Only for Medium Voltage for now */} {categoryFileSlug === 'medium-voltage-cables' && datasheetPath && (

    {t('downloadDatasheet')}

    )} {/* Structured Data */} ({ '@type': 'PropertyValue', name: item.label, value: item.value, })), category: product.frontmatter.categories.join(', '), mainEntityOfPage: { '@type': 'WebPage', '@id': `${SITE_URL}/${locale}/products/${slug.join('/')}`, }, } as any } />
    {/* Related Products Section */}
    ); }