import React, { useEffect } from 'react'; import { Head, usePage, router } from '@inertiajs/react'; import { useTranslation } from 'react-i18next'; import MatomoTracker, { MatomoConfig } from '@/components/analytics/MatomoTracker'; import CookieBanner from '@/components/consent/CookieBanner'; interface MarketingLayoutProps { children: React.ReactNode; title?: string; } const MarketingLayout: React.FC = ({ children, title }) => { const page = usePage<{ translations?: Record>; locale?: string; analytics?: { matomo?: MatomoConfig }; }>(); const { url } = page; const { t } = useTranslation('marketing'); const i18n = useTranslation(); const { locale, analytics } = page.props; useEffect(() => { if (locale && i18n.i18n.language !== locale) { i18n.i18n.changeLanguage(locale); } }, [locale, i18n]); const marketing = page.props.translations?.marketing ?? {}; const getString = (key: string, fallback: string) => { const value = marketing[key]; return typeof value === 'string' ? value : fallback; }; const activeLocale = locale || 'de'; const alternateLocale = activeLocale === 'de' ? 'en' : 'de'; const path = url.replace(/^\/(de|en)/, ''); const canonicalUrl = `https://fotospiel.app${path || '/'}`; const handleLocaleChange = (nextLocale: string) => { router.post('/set-locale', { locale: nextLocale }, { preserveState: true, replace: true, onSuccess: () => { i18n.i18n.changeLanguage(nextLocale); }, }); }; return ( <> {title || t('meta.title', getString('title', 'Fotospiel'))}
{children}
{/* Footer kommt von Footer.tsx */}
); }; export default MarketingLayout;