'use client';

import { useTranslations } from 'next-intl';
import { getTranslations } from 'next-intl/server';
import { Metadata } from 'next';
import JsonLd from '@/components/JsonLd';
import { getBreadcrumbSchema, SITE_URL } from '@/lib/schema';
import { Section, Container, Heading, Badge, Button } from '@/components/ui';
import Image from 'next/image';
import Lightbox from '@/components/Lightbox';
import Reveal from '@/components/Reveal';

interface TeamPageProps {
  params: {
    locale: string;
  };
}

export async function generateMetadata({ params: { locale } }: TeamPageProps): Promise<Metadata> {
  const t = await getTranslations({ locale, namespace: 'Team' });
  return {
    title: t('hero.subtitle'),
    description: t('hero.title'),
    alternates: {
      canonical: `/${locale}/team`,
      languages: {
        'de': '/de/team',
        'en': '/en/team',
        'x-default': '/en/team',
      },
    },
    openGraph: {
      title: `${t('hero.subtitle')} | KLZ Cables`,
      description: t('hero.title'),
      url: `https://klz-cables.com/${locale}/team`,
    },
    twitter: {
      card: 'summary_large_image',
      title: `${t('hero.subtitle')} | KLZ Cables`,
      description: t('hero.title'),
    },
  };
}

export default function TeamPage() {
  const t = useTranslations('Team');

  const [lightboxOpen, setLightboxOpen] = React.useState(false);
  const [lightboxIndex, setLightboxIndex] = React.useState(0);

  const teamGalleryImages = [
    '/uploads/2024/12/DSC07539-Large-600x400.webp',
    '/uploads/2024/12/DSC07460-Large-600x400.webp',
    '/uploads/2024/12/DSC07469-Large-600x400.webp',
    '/uploads/2024/12/DSC07433-Large-600x400.webp',
    '/uploads/2024/12/DSC07387-Large-600x400.webp'
  ];

  return (
    <div className="flex flex-col min-h-screen bg-neutral-light">
      <JsonLd
        id="breadcrumb-team"
        data={getBreadcrumbSchema([
          { name: t('hero.subtitle'), item: `/team` },
        ])}
      />
      <JsonLd
        id="person-michael"
        data={{
          '@context': 'https://schema.org',
          '@type': 'Person',
          name: t('michael.name'),
          jobTitle: t('michael.role'),
          worksFor: {
            '@type': 'Organization',
            name: 'KLZ Cables',
          },
          sameAs: [
            'https://www.linkedin.com/in/michael-bodemer-33b493122/'
          ],
          image: `${SITE_URL}/uploads/2024/12/DSC07768-Large.webp`
        }}
      />
      <JsonLd
        id="person-klaus"
        data={{
          '@context': 'https://schema.org',
          '@type': 'Person',
          name: t('klaus.name'),
          jobTitle: t('klaus.role'),
          worksFor: {
            '@type': 'Organization',
            name: 'KLZ Cables',
          },
          sameAs: [
            'https://www.linkedin.com/in/klaus-mintel-b80a8b193/'
          ],
          image: `${SITE_URL}/uploads/2024/12/DSC07963-Large.webp`
        }}
      />
      {/* Hero Section */}
      <section className="relative flex items-center justify-center overflow-hidden bg-primary-dark pt-32 pb-24 md:pt-[14%] md:pb-[12%]">
        <div className="absolute inset-0 z-0">
          <Image 
            src="/uploads/2024/12/DSC07655-Large.webp" 
            alt="KLZ Team" 
            fill
            className="object-cover scale-105 animate-slow-zoom opacity-30 md:opacity-40"
            priority
          />
          <div className="absolute inset-0 bg-gradient-to-b from-primary-dark/80 via-primary-dark/40 to-primary-dark/80" />
        </div>
        
        <Container className="relative z-10 text-center text-white max-w-5xl animate-slide-up">
          <Badge variant="saturated" className="mb-4 md:mb-8 shadow-lg">{t('hero.badge')}</Badge>
          <h1 className="text-3xl md:text-6xl lg:text-7xl font-extrabold tracking-tight leading-[1.1] mb-4 md:mb-8">
            {t('hero.subtitle')}
          </h1>
          <p className="text-lg md:text-2xl text-white/70 font-medium italic">
            {t('hero.title')}
          </p>
        </Container>
      </section>

      {/* Michael Bodemer Section - Sticky Narrative Split Layout */}
      <section className="relative bg-white overflow-hidden">
        <div className="flex flex-col lg:flex-row">
          <Reveal className="w-full lg:w-1/2 p-6 md:p-24 lg:p-32 flex flex-col justify-center bg-primary-dark text-white relative order-2 lg:order-1">
            <div className="absolute top-0 right-0 w-32 h-full bg-accent/5 -skew-x-12 translate-x-1/2" />
            <div className="relative z-10">
              <Badge variant="accent" className="mb-4 md:mb-8">{t('michael.role')}</Badge>
              <Heading level={2} className="text-white mb-6 md:mb-10 text-3xl md:text-5xl">
                <span className="text-white">{t('michael.name')}</span>
              </Heading>
              <div className="relative mb-6 md:mb-12">
                <div className="absolute -left-4 md:-left-8 top-0 bottom-0 w-1 md:w-1.5 bg-accent rounded-full" />
                <p className="text-lg md:text-2xl font-bold italic leading-relaxed pl-5 md:pl-8 text-white/90">
                  {t('michael.quote')}
                </p>
              </div>
              <p className="text-base md:text-xl leading-relaxed text-white/70 mb-6 md:mb-12 max-w-xl">
                {t('michael.description')}
              </p>
              <Button 
                href="https://www.linkedin.com/in/michael-bodemer-33b493122/" 
                variant="accent" 
                size="lg"
                className="group w-full md:w-auto md:h-16 md:px-10 md:text-xl active:scale-95 transition-transform"
              >
                {t('michael.linkedin')}
                <span className="ml-3 transition-transform group-hover:translate-x-2">&rarr;</span>
              </Button>
            </div>
          </Reveal>
          <div className="w-full lg:w-1/2 relative min-h-[400px] md:min-h-[600px] lg:min-h-screen overflow-hidden order-1 lg:order-2">
            <Image 
              src="/uploads/2024/12/DSC07768-Large.webp" 
              alt={t('michael.name')} 
              fill 
              className="object-cover scale-105 hover:scale-100 transition-transform duration-1000"
              sizes="(max-width: 1024px) 100vw, 50vw"
            />
            <div className="absolute inset-0 bg-gradient-to-t from-primary-dark/60 lg:bg-gradient-to-r lg:from-primary-dark/20 to-transparent" />
          </div>
        </div>
      </section>

      {/* Legacy Section - Immersive Background */}
      <section className="relative py-16 md:py-48 bg-primary-dark text-white overflow-hidden">
        <div className="absolute inset-0 z-0">
          <Image 
            src="/uploads/2024/12/1694273920124-copy.webp" 
            alt={t('legacy.subtitle')} 
            fill
            className="object-cover opacity-20 md:opacity-30 scale-110 animate-slow-zoom"
            sizes="100vw"
          />
          <div className="absolute inset-0 bg-primary-dark/60 mix-blend-multiply" />
        </div>
        <Container className="relative z-10">
          <div className="grid grid-cols-1 lg:grid-cols-12 gap-8 md:gap-16 items-center">
            <div className="lg:col-span-6">
              <Heading level={2} subtitle={t('legacy.subtitle')} className="text-white mb-6 md:mb-10">
                <span className="text-white">{t('legacy.title')}</span>
              </Heading>
              <div className="space-y-4 md:space-y-8 text-base md:text-2xl text-white/80 leading-relaxed font-medium">
                <p className="border-l-4 border-accent pl-5 md:pl-8 py-2 bg-white/5 backdrop-blur-sm rounded-r-xl md:rounded-r-2xl">
                  {t('legacy.p1')}
                </p>
                <p className="pl-6 md:pl-9 line-clamp-3 md:line-clamp-none">
                  {t('legacy.p2')}
                </p>
              </div>
            </div>
            <div className="lg:col-span-6 grid grid-cols-2 md:grid-cols-2 gap-3 md:gap-6">
              <div className="p-4 md:p-8 bg-white/5 backdrop-blur-md border border-white/10 rounded-2xl md:rounded-[32px] hover:bg-white/10 transition-colors">
                <div className="text-xl md:text-4xl font-extrabold text-accent mb-1 md:mb-2">{t('legacy.expertise')}</div>
                <div className="text-[10px] md:text-sm font-bold uppercase tracking-widest text-white/50">{t('legacy.expertiseDesc')}</div>
              </div>
              <div className="p-4 md:p-8 bg-white/5 backdrop-blur-md border border-white/10 rounded-2xl md:rounded-[32px] hover:bg-white/10 transition-colors">
                <div className="text-xl md:text-4xl font-extrabold text-accent mb-1 md:mb-2">{t('legacy.network')}</div>
                <div className="text-[10px] md:text-sm font-bold uppercase tracking-widest text-white/50">{t('legacy.networkDesc')}</div>
              </div>
            </div>
          </div>
        </Container>
      </section>

      {/* Klaus Mintel Section - Reversed Split Layout */}
      <section className="relative bg-white overflow-hidden">
        <div className="flex flex-col lg:flex-row">
          <div className="w-full lg:w-1/2 relative min-h-[400px] md:min-h-[600px] lg:min-h-screen overflow-hidden order-1">
            <Image 
              src="/uploads/2024/12/DSC07963-Large.webp" 
              alt={t('klaus.name')} 
              fill 
              className="object-cover scale-105 hover:scale-100 transition-transform duration-1000"
              sizes="(max-width: 1024px) 100vw, 50vw"
            />
            <div className="absolute inset-0 bg-gradient-to-t from-white/60 lg:bg-gradient-to-l lg:from-primary-dark/20 to-transparent" />
          </div>
          <Reveal className="w-full lg:w-1/2 p-6 md:p-24 lg:p-32 flex flex-col justify-center bg-neutral-light text-saturated relative order-2">
            <div className="absolute top-0 left-0 w-32 h-full bg-saturated/5 skew-x-12 -translate-x-1/2" />
            <div className="relative z-10">
              <Badge variant="saturated" className="mb-4 md:mb-8">{t('klaus.role')}</Badge>
              <Heading level={2} className="text-saturated mb-6 md:mb-10 text-3xl md:text-6xl">
                {t('klaus.name')}
              </Heading>
              <div className="relative mb-6 md:mb-12">
                <div className="absolute -left-4 md:-left-8 top-0 bottom-0 w-1 md:w-1.5 bg-saturated rounded-full" />
                <p className="text-lg md:text-3xl font-bold italic leading-relaxed pl-5 md:pl-8 text-text-secondary">
                  {t('klaus.quote')}
                </p>
              </div>
              <p className="text-base md:text-xl leading-relaxed text-text-secondary mb-6 md:mb-12 max-w-xl">
                {t('klaus.description')}
              </p>
              <Button 
                href="https://www.linkedin.com/in/klaus-mintel-b80a8b193/" 
                variant="saturated" 
                size="lg"
                className="group w-full md:w-auto md:h-16 md:px-10 md:text-xl active:scale-95 transition-transform"
              >
                {t('klaus.linkedin')}
                <span className="ml-3 transition-transform group-hover:translate-x-2">&rarr;</span>
              </Button>
            </div>
          </Reveal>
        </div>
      </section>

      {/* Manifesto Section - Modern Grid */}
      <Section className="bg-white text-primary py-16 md:py-28">
        <Container>
          <div className="sticky-narrative-container">
            <div className="sticky-narrative-sidebar mb-8 lg:mb-0">
              <div className="lg:sticky lg:top-32">
                <Heading level={2} subtitle={t('manifesto.subtitle')} className="mb-4 md:mb-8">
                  {t('manifesto.title')}
                </Heading>
                <p className="text-base md:text-xl text-text-secondary leading-relaxed">
                  {t('manifesto.tagline')}
                </p>
                
                {/* Mobile-only progress indicator */}
                <div className="flex lg:hidden mt-8 gap-2">
                  {[0, 1, 2, 3, 4, 5].map((i) => (
                    <div key={i} className="h-1.5 flex-1 bg-neutral-medium rounded-full overflow-hidden">
                      <div className="h-full bg-accent w-0 group-active:w-full transition-all duration-500" />
                    </div>
                  ))}
                </div>
              </div>
            </div>
            <div className="sticky-narrative-content grid grid-cols-1 md:grid-cols-2 gap-4 md:gap-10">
              {[0, 1, 2, 3, 4, 5].map((idx) => (
                <div key={idx} className="p-6 md:p-10 bg-neutral-light rounded-2xl md:rounded-[40px] border border-transparent hover:border-accent hover:bg-white hover:shadow-2xl transition-all duration-500 group active:scale-[0.98] touch-target-none">
                  <div className="w-10 h-10 md:w-16 md:h-16 bg-white rounded-xl md:rounded-2xl flex items-center justify-center mb-4 md:mb-8 shadow-sm group-hover:bg-accent transition-colors duration-500">
                    <span className="text-primary font-extrabold text-lg md:text-2xl group-hover:text-primary-dark">0{idx + 1}</span>
                  </div>
                  <h3 className="text-lg md:text-2xl font-bold mb-2 md:mb-4 text-primary">{t(`manifesto.items.${idx}.title`)}</h3>
                  <p className="text-sm md:text-lg text-text-secondary leading-relaxed">{t(`manifesto.items.${idx}.description`)}</p>
                </div>
              ))}
            </div>
          </div>
        </Container>
      </Section>

      {/* Gallery Section - Premium Treatment */}
      <Section className="bg-primary-dark py-16 md:py-32">
        <Container>
          <Heading level={2} subtitle={t('gallery.subtitle')} align="center" className="text-white mb-12 md:mb-20">
            <span className="text-white">{t('gallery.title')}</span>
          </Heading>
          <div className="grid grid-cols-2 md:grid-cols-5 gap-3 md:gap-6">
            {teamGalleryImages.map((src, idx) => (
              <button
                key={idx}
                onClick={() => {
                  setLightboxIndex(idx);
                  setLightboxOpen(true);
                }}
                className="relative aspect-[3/4] rounded-2xl md:rounded-[32px] overflow-hidden group shadow-2xl cursor-pointer"
              >
                <Image src={src} alt={t('gallery.title')} fill className="object-cover transition-transform duration-1000 group-hover:scale-110" />
                <div className="absolute inset-0 bg-primary-dark/40 group-hover:bg-transparent transition-all duration-500" />
                <div className="absolute inset-0 border-0 group-hover:border-[8px] md:group-hover:border-[12px] border-white/10 transition-all duration-500 pointer-events-none" />
              </button>
            ))}
          </div>
        </Container>

        <Lightbox
          isOpen={lightboxOpen}
          images={teamGalleryImages}
          initialIndex={lightboxIndex}
          onClose={() => setLightboxOpen(false)}
        />
      </Section>
    </div>
  );
}
