import { setRequestLocale } from 'next-intl/server';
import type { Metadata } from 'next';
import { getTranslations } from 'next-intl/server';
import Link from 'next/link';

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 t = await getTranslations({ locale, namespace: 'pages.terms.seo' });

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

  return {
    title: t('title'),
    description: t('description'),
    alternates: {
      canonical: `${BASE_URL}${localePath}`,
      languages: {
        'x-default': `${BASE_URL}/terms`,
        de: `${BASE_URL}/terms`,
        en: `${BASE_URL}/en/terms`,
        sr: `${BASE_URL}/sr/terms`,
      },
    },
    openGraph: {
      title: t('title'),
      description: t('description'),
      url: `${BASE_URL}${localePath}`,
      type: 'website',
      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')),
    },
    robots: {
      index: true,
      follow: true,
    },
  };
}

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

  const t = await getTranslations('pages.terms');

  return (
    <main className="min-h-screen py-20 px-4">
      <div className="max-w-4xl mx-auto">
        {/* Breadcrumb */}
        <nav className="mb-8">
          <Link href={`/${locale}`} className="text-zinc-400 hover:text-white transition-colors">
            Home
          </Link>
          <span className="text-zinc-600 mx-2">/</span>
          <span className="text-white">{t('content.title')}</span>
        </nav>

        <article className="prose prose-invert prose-zinc max-w-none">
          <h1>{t('content.title')}</h1>
          <p className="text-zinc-400">{t('content.lastUpdated')}</p>

          <h2>1. Agreement to Terms</h2>
          <p>
            By accessing our website, you agree to be bound by these Terms and Conditions
            and to comply with all applicable laws and regulations.
          </p>

          <h2>2. Intellectual Property</h2>
          <p>
            All content on this website, including text, graphics, logos, images, and software,
            is the property of Damjan Savić and is protected by intellectual property laws.
          </p>

          <h2>3. User Responsibilities</h2>
          <p>
            When using our website, you agree to provide accurate information,
            use the website legally and ethically, and not attempt unauthorized access.
          </p>

          <h2>4. Limitation of Liability</h2>
          <p>
            We are not liable for any indirect, incidental, special, or consequential damages
            arising from your use of or inability to use the website.
          </p>

          <h2>5. Governing Law</h2>
          <p>
            These terms are governed by and construed in accordance with the laws of Germany.
          </p>

          <h2>6. Contact</h2>
          <p>
            For questions about these terms, please contact us at:
            <br />
            Email: legal@damjan-savic.com
          </p>
        </article>
      </div>
    </main>
  );
}
