import { setRequestLocale } from 'next-intl/server';
import { Hero, Experience, Skills, Projects, About } from '@/components/sections';
import type { Metadata } from 'next';

type Props = {
  params: Promise<{ locale: string }>;
};

const BASE_URL = process.env.NEXT_PUBLIC_SITE_URL || 'https://damjan-savic.com';

export async function generateMetadata({ params }: Props): Promise<Metadata> {
  const { locale } = await params;

  const titles: Record<string, string> = {
    de: 'KI Entwickler Köln | AI Agents & Automatisierung | Damjan Savić',
    en: 'AI Developer Cologne | AI Agents & Automation | Damjan Savić',
    sr: 'AI Developer Keln | AI Agenti & Automatizacija | Damjan Savić',
  };

  const descriptions: Record<string, string> = {
    de: 'Freelance KI Entwickler aus Köln. Spezialisiert auf KI-Agenten, Voice AI, Prozessautomatisierung mit n8n und SaaS-Entwicklung. Über 7 Jahre Erfahrung.',
    en: 'Remote AI Developer & Automation Expert based in Germany. Building AI agents, Voice AI systems, and n8n automations for clients in USA, UK, and Europe. 7+ years experience. Available for international projects.',
    sr: 'AI Developer i Automation Specialist iz Nemačke, poreklo iz Srbije. Specijalizovan za AI agente, Voice AI, n8n automatizaciju i SaaS razvoj. Radim sa klijentima iz Srbije, Nemačke i dijaspore. 7+ godina iskustva.',
  };

  const keywords: Record<string, string[]> = {
    de: [
      'KI Entwickler Köln',
      'AI Developer Deutschland',
      'KI Entwickler DACH',
      'AI Agentur Köln',
      'Prozessautomatisierung',
      'n8n Entwickler',
      'Voice AI',
      'KI-Agenten',
      'Fullstack Entwickler',
      'SaaS Entwicklung',
      'Automatisierung',
      'GPT-4 Integration',
      'KI Entwickler Wien',
      'AI Developer Zürich',
      'Freelancer Deutschland',
      'Claude AI Integration',
    ],
    en: [
      'AI Developer',
      'Remote AI Developer',
      'AI Developer USA',
      'AI Developer UK',
      'AI Developer Europe',
      'Process Automation Expert',
      'n8n Developer',
      'Voice AI Developer',
      'AI Agents Developer',
      'Fullstack Developer',
      'SaaS Development',
      'GPT-4 Integration',
      'ChatGPT Integration',
      'Remote Developer',
      'Freelance AI Developer',
      'AI Consultant',
      'Automation Specialist',
    ],
    sr: [
      'AI Developer Srbija',
      'AI Programer Beograd',
      'AI Developer Novi Sad',
      'Fullstack Programer Srbija',
      'Automatizacija procesa',
      'n8n Automatizacija',
      'Voice AI Srbija',
      'AI Agenti',
      'SaaS Razvoj',
      'GPT-4 Integracija',
      'Python Programer Srbija',
      'React Programer Beograd',
      'Freelance Developer Srbija',
      'Remote Programer Nemačka',
      'Srpski Developer Dijaspora',
      'Web Razvoj Beograd',
    ],
  };

  const localePath = locale === 'de' ? '' : `/${locale}`;

  return {
    title: titles[locale] || titles.de,
    description: descriptions[locale] || descriptions.de,
    keywords: keywords[locale] || keywords.de,
    alternates: {
      canonical: `${BASE_URL}${localePath || '/'}`,
      languages: {
        'x-default': `${BASE_URL}/`,
        de: `${BASE_URL}/`,
        en: `${BASE_URL}/en`,
        sr: `${BASE_URL}/sr`,
      },
    },
    openGraph: {
      title: titles[locale] || titles.de,
      description: descriptions[locale] || descriptions.de,
      url: `${BASE_URL}${localePath || '/'}`,
      siteName: 'Damjan Savić',
      locale: locale === 'de' ? 'de_DE' : locale === 'sr' ? 'sr_RS' : 'en_US',
      alternateLocale: ['de_DE', 'en_US', 'sr_RS'].filter(l => l !== (locale === 'de' ? 'de_DE' : locale === 'sr' ? 'sr_RS' : 'en_US')),
      type: 'website',
      images: [
        {
          url: `${BASE_URL}/images/og-image.jpg`,
          width: 1200,
          height: 630,
          alt: 'Damjan Savić - AI & Automation Specialist',
        },
      ],
    },
    twitter: {
      card: 'summary_large_image',
      title: titles[locale] || titles.de,
      description: descriptions[locale] || descriptions.de,
      images: [`${BASE_URL}/images/og-image.jpg`],
    },
  };
}

export default async function HomePage({ params }: Props) {
  const { locale } = await params;
  setRequestLocale(locale);

  return (
    <>
      <Hero />
      <Experience />
      <Skills />
      <Projects />
      <About />
    </>
  );
}
