import { notFound, redirect } from 'next/navigation';
import { Container, Badge, Heading } from '@/components/ui';
import { getTranslations, setRequestLocale } from 'next-intl/server';
import { Metadata } from 'next';
import { getPageBySlug } from '@/lib/pages';
import { mapSlugToFileSlug, mapFileSlugToTranslated } from '@/lib/slugs';
import { MDXRemote } from 'next-mdx-remote/rsc';
import { SITE_URL } from '@/lib/schema';
import TrackedLink from '@/components/analytics/TrackedLink';
import { getButtonClasses, ButtonOverlay } from '@/components/ui/Button';
import { getAllReferences } from '@/lib/references';
import { defaultLocations, minorLocations } from '@/lib/map-data';
// Import components used in MDX
import { HeroVideo as HomeHero } from '@/components/blocks/HeroVideo';
import { SubCompanyTiles as HomeSubCompanyTiles } from '@/components/blocks/SubCompanyTiles';
import { CompetenceBentoGrid as HomeCompetenceBentoGrid } from '@/components/blocks/CompetenceBentoGrid';
import { ReferencesSlider as HomeReferencesSlider } from '@/components/blocks/ReferencesSlider';
import { CompanyTimeline } from '@/components/blocks/CompanyTimeline';
import { JobListingBlock } from '@/components/blocks/JobListingBlock';
import { ServiceDetailGrid } from '@/components/blocks/ServiceDetailGrid';
import { BenefitGrid } from '@/components/blocks/BenefitGrid';
import { InteractiveGermanyMap } from '@/components/blocks/InteractiveGermanyMap';
import { FaqBlock } from '@/components/blocks/FaqBlock';
import { CertificatesBlock } from '@/components/blocks/CertificatesBlock';
import { HeroSection } from '@/components/blocks/HeroSection';
import { TeamGrid } from '@/components/blocks/TeamGrid';
import { DeepDrillAnimation } from '@/components/blocks/DeepDrillAnimation';
import { DataGridPulse } from '@/components/blocks/DataGridPulse';
import { GrowthChart } from '@/components/blocks/GrowthChart';
import JsonLd from '@/components/JsonLd';
import { Button } from '@/components/ui/Button';
import { AnimatedCounter } from '@/components/ui';
const mdxComponents = {
HomeHero,
HomeSubCompanyTiles,
HomeCompetenceBentoGrid,
HomeReferencesSlider,
CompanyTimeline,
JobListingBlock,
ServiceDetailGrid,
BenefitGrid,
InteractiveGermanyMap,
FaqBlock,
CertificatesBlock,
HeroSection,
TeamGrid,
JsonLd,
Button,
Badge,
AnimatedCounter,
GrowthChart,
DeepDrillAnimation,
DataGridPulse,
// Standard HTML element mapping for consistent E-TIB typography
h1: (props: any) => , // Hidden because Hero handles H1
h2: (props: any) => ,
h3: (props: any) => ,
h4: (props: any) => ,
p: (props: any) =>
,
ul: (props: any) => ,
ol: (props: any) =>
,
li: (props: any) => (
),
a: (props: any) => ,
strong: (props: any) => ,
blockquote: (props: any) => (
),
hr: (props: any) =>
,
img: (props: any) =>
,
};
interface PageProps {
params: Promise<{
locale: string;
slug: string;
}>;
}
export async function generateMetadata({ params }: PageProps): Promise {
const { locale, slug } = await params;
// Guard against invalid locales
if (locale !== 'de' && locale !== 'en') return {};
const pageData = await getPageBySlug(slug, locale);
if (!pageData) return {};
const fileSlug = await mapSlugToFileSlug(pageData.slug || slug, locale);
const deSlug = await mapFileSlugToTranslated(fileSlug, 'de');
const enSlug = await mapFileSlugToTranslated(fileSlug, 'en');
// Determine correct localized slug based on current locale
const currentLocaleSlug = locale === 'de' ? deSlug : enSlug;
return {
title: pageData.frontmatter.title,
description: pageData.frontmatter.excerpt || '',
alternates: {
canonical: `${SITE_URL}/${locale}/${currentLocaleSlug}`,
languages: {
de: `${SITE_URL}/de/${deSlug}`,
en: `${SITE_URL}/en/${enSlug}`,
'x-default': `${SITE_URL}/en/${enSlug}`,
},
},
openGraph: {
title: `${pageData.frontmatter.title} | E-TIB`,
description: pageData.frontmatter.excerpt || '',
url: `${SITE_URL}/${locale}/${currentLocaleSlug}`,
},
twitter: {
card: 'summary_large_image',
title: `${pageData.frontmatter.title} | E-TIB`,
description: pageData.frontmatter.excerpt || '',
},
};
}
export default async function Page(props: { params: Promise<{ locale: string; slug: string }> }) {
const { locale, slug } = await props.params;
// Guard against invalid locales (e.g. favicon.ico) hitting the DB
if (locale !== 'de' && locale !== 'en') {
notFound();
}
setRequestLocale(locale);
const pageData = await getPageBySlug(slug, locale);
const t = await getTranslations('StandardPage');
if (!pageData) {
notFound();
}
// Redirect logic removed to simplify for now, as slugs match file names
/*
const fileSlug = await mapSlugToFileSlug(pageData.slug || slug, locale);
const correctSlug = await mapFileSlugToTranslated(fileSlug, locale);
if (correctSlug && correctSlug !== slug) {
redirect(`/${locale}/${correctSlug}`);
}
*/
// Determine layout type
const isFullBleed = pageData.frontmatter.layout === 'fullBleed';
// Fetch references to enrich the map if it's used
const references = await getAllReferences(locale);
const allLocations = [...defaultLocations, ...minorLocations];
const enrichedLocations = allLocations.map(loc => {
if (loc.type === 'project') {
const ref = references.find(r => r.slug === loc.id);
if (ref) {
return {
...loc,
featuredImage: ref.frontmatter.featuredImage,
details: [
ref.frontmatter.client || t('client'),
ref.frontmatter.dateString || new Date(ref.frontmatter.date).getFullYear().toString(),
],
};
}
}
return loc;
});
const pageMdxComponents = {
...mdxComponents,
InteractiveGermanyMap: (props: any) => ,
HomeReferencesSlider: (props: any) => ({
id: r.slug,
slug: r.slug,
title: r.frontmatter.title,
category: Array.isArray(r.frontmatter.category) ? r.frontmatter.category[0] : (r.frontmatter.category || 'Projekt'),
image: r.frontmatter.featuredImage
}))} />,
};
return (
{/* Generic Hero Section (only for standard pages) */}
{!isFullBleed && (
{t('badge')}
{pageData.frontmatter.title}
)}
{/* Main Content Area */}
{isFullBleed ? (
) : (
{/* Excerpt/Lead paragraph if available */}
{pageData.frontmatter.excerpt && (
{pageData.frontmatter.excerpt}
)}
{/* Main content */}
)}
{/* Support Section */}
{t('needHelp')}
{t('supportTeamAvailable')}
{t('contactUs')}
→
);
}