import ProductSidebar from '@/components/ProductSidebar'; import ProductTabs from '@/components/ProductTabs'; import ProductTechnicalData from '@/components/ProductTechnicalData'; import RelatedProducts from '@/components/RelatedProducts'; import { Badge, Container, Section } from '@/components/ui'; import { getDatasheetPath } from '@/lib/datasheets'; import { getAllProducts, getProductBySlug } from '@/lib/mdx'; import { Metadata } from 'next'; import { getTranslations } from 'next-intl/server'; import { MDXRemote } from 'next-mdx-remote/rsc'; import Image from 'next/image'; import Link from 'next/link'; import { notFound } from 'next/navigation'; interface ProductPageProps { params: { locale: string; slug: string[]; }; } export async function generateMetadata({ params }: ProductPageProps): Promise { const { locale, slug } = 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']; if (categories.includes(productSlug)) { const categoryKey = productSlug.replace(/-cables$/, '').replace(/-([a-z])/g, (g) => g[1].toUpperCase()); const categoryTitle = t(`categories.${categoryKey}.title`); const categoryDesc = t(`categories.${categoryKey}.description`); return { title: categoryTitle, description: categoryDesc, openGraph: { title: categoryTitle, description: categoryDesc, url: `https://klz-cables.com/${locale}/products/${productSlug}`, } }; } const product = await getProductBySlug(productSlug, locale); if (!product) return {}; return { title: product.frontmatter.title, description: product.frontmatter.description, openGraph: { title: product.frontmatter.title, description: product.frontmatter.description, type: 'website', url: `https://klz-cables.com/${locale}/products/${slug.join('/')}`, }, twitter: { card: 'summary_large_image', title: product.frontmatter.title, description: product.frontmatter.description, }, }; } const components = { ProductTechnicalData, ProductTabs, p: (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 } = 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']; if (categories.includes(productSlug)) { const allProducts = await getAllProducts(locale); const categoryKey = productSlug.replace(/-cables$/, '').replace(/-([a-z])/g, (g) => g[1].toUpperCase()); const categoryTitle = t(`categories.${categoryKey}.title`); // Filter products for this category const filteredProducts = allProducts.filter(p => p.frontmatter.categories.some(cat => cat.toLowerCase().replace(/\s+/g, '-') === productSlug) ); return (

    {categoryTitle}

    {filteredProducts.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(); } const datasheetPath = getDatasheetPath(productSlug, locale); const isFallback = (product.frontmatter as any).isFallback; const categorySlug = slug[0]; const categoryKey = categorySlug.replace(/-cables$/, '').replace(/-([a-z])/g, (g) => g[1].toUpperCase()); const categoryTitle = t(`categories.${categoryKey}.title`); 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(/]*>(.*?)<\/h2>/g, '\n## $1\n') .replace(/]*>(.*?)<\/h3>/g, '\n### $1\n') .replace(/]*>(.*?)<\/p>/g, '\n$1\n') .replace(/]*>(.*?)<\/ul>/gs, '\n$1\n') .replace(/]*>(.*?)<\/li>/g, '\n- $1\n') .replace(/]*>(.*?)<\/strong>/g, '**$1**') .replace(/]*>/g, '') .replace(/<\/section>/g, ''); 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 */}
    {/* Structured Data */}