'use client';

import { useRef } from 'react';
import { useTranslations } from 'next-intl';
import { motion, useInView } from 'framer-motion';
import {
  Shield,
  UserCheck,
  Database,
  FileText,
  Globe,
  Clock,
  CheckCircle,
  Download,
  Trash2,
  Edit,
  Eye,
  Mail,
  type LucideIcon,
} from 'lucide-react';
import { Link } from '@/i18n/navigation';
import { LandingHeader, LandingFooter } from '@/components/layout';

type RightKey = 'access' | 'rectification' | 'erasure' | 'portability';
type PrincipleKey = 'minimization' | 'retention' | 'integrity' | 'transparency';
type MeasureKey = 'technical' | 'organizational';

const RIGHTS: { key: RightKey; icon: LucideIcon }[] = [
  { key: 'access', icon: Eye },
  { key: 'rectification', icon: Edit },
  { key: 'erasure', icon: Trash2 },
  { key: 'portability', icon: Download },
];

const PRINCIPLES: { key: PrincipleKey; icon: LucideIcon }[] = [
  { key: 'minimization', icon: Database },
  { key: 'retention', icon: Clock },
  { key: 'integrity', icon: Shield },
  { key: 'transparency', icon: FileText },
];

const MEASURES: MeasureKey[] = ['technical', 'organizational'];
const MEASURE_ITEMS = ['item1', 'item2', 'item3', 'item4', 'item5'] as const;
const REGISTER_ITEMS = ['item1', 'item2', 'item3', 'item4', 'item5'] as const;

export default function CompliancePage() {
  const t = useTranslations('marketing.compliance');
  const heroRef = useRef(null);
  const contentRef = useRef(null);

  const isHeroInView = useInView(heroRef, { once: true });
  const isContentInView = useInView(contentRef, { once: true });

  const containerVariants = {
    hidden: { opacity: 0, y: 50 },
    visible: {
      opacity: 1,
      y: 0,
      transition: {
        duration: 0.6,
        staggerChildren: 0.1,
      },
    },
  };

  const itemVariants = {
    hidden: { opacity: 0, y: 20 },
    visible: {
      opacity: 1,
      y: 0,
      transition: { duration: 0.5 },
    },
  };

  return (
    <div className="min-h-screen bg-white">
      <LandingHeader />

      {/* Hero Section */}
      <section
        ref={heroRef}
        className="relative pt-32 pb-20 bg-gradient-to-br from-brand-navy to-brand-navy/95 overflow-hidden"
      >
        <div className="absolute inset-0 opacity-10">
          <div className="absolute top-20 left-20 w-96 h-96 bg-brand-turquoise rounded-full blur-3xl" />
          <div className="absolute bottom-20 right-20 w-96 h-96 bg-brand-green rounded-full blur-3xl" />
        </div>

        <div className="relative z-10 max-w-7xl mx-auto px-6 lg:px-8">
          <motion.div
            initial={{ opacity: 0, y: 30 }}
            animate={isHeroInView ? { opacity: 1, y: 0 } : {}}
            transition={{ duration: 0.8 }}
            className="text-center"
          >
            <motion.div
              initial={{ scale: 0.8, opacity: 0 }}
              animate={isHeroInView ? { scale: 1, opacity: 1 } : {}}
              transition={{ duration: 0.6, delay: 0.2 }}
              className="inline-flex items-center space-x-2 bg-white/10 backdrop-blur-sm px-4 py-2 rounded-full mb-8 border border-white/20"
            >
              <Globe className="w-5 h-5 text-brand-turquoise" />
              <span className="text-white/90 text-sm font-medium">{t('badge')}</span>
            </motion.div>

            <h1 className="text-4xl lg:text-6xl font-bold text-white mb-6 leading-tight">
              {t('title1')}
              <br />
              <span className="text-transparent bg-clip-text bg-gradient-to-r from-brand-turquoise to-brand-green">
                {t('title2')}
              </span>
            </h1>

            <p className="text-xl text-white/80 mb-6 max-w-3xl mx-auto leading-relaxed">
              {t('intro')}
            </p>

            <div className="flex items-center justify-center space-x-4">
              <div className="flex items-center space-x-2 bg-white/10 px-4 py-2 rounded-lg">
                <CheckCircle className="w-5 h-5 text-brand-green" />
                <span className="text-white text-sm">{t('badges.compliant')}</span>
              </div>
              <div className="flex items-center space-x-2 bg-white/10 px-4 py-2 rounded-lg">
                <UserCheck className="w-5 h-5 text-brand-green" />
                <span className="text-white text-sm">{t('badges.dpo')}</span>
              </div>
            </div>
          </motion.div>
        </div>

        {/* Wave */}
        <div className="absolute bottom-0 left-0 right-0">
          <svg className="w-full h-16" viewBox="0 0 1440 60" preserveAspectRatio="none">
            <path
              d="M0,30 C240,50 480,10 720,30 C960,50 1200,10 1440,30 L1440,60 L0,60 Z"
              fill="white"
            />
          </svg>
        </div>
      </section>

      {/* Your Rights */}
      <section ref={contentRef} className="py-20">
        <div className="max-w-7xl mx-auto px-6 lg:px-8">
          <motion.div
            initial={{ opacity: 0, y: 30 }}
            animate={isContentInView ? { opacity: 1, y: 0 } : {}}
            transition={{ duration: 0.8 }}
            className="text-center mb-16"
          >
            <h2 className="text-3xl lg:text-4xl font-bold text-brand-navy mb-4">
              {t('rightsTitle')}
            </h2>
            <p className="text-xl text-gray-600 max-w-2xl mx-auto">{t('rightsSubtitle')}</p>
          </motion.div>

          <motion.div
            variants={containerVariants}
            initial="hidden"
            animate={isContentInView ? 'visible' : 'hidden'}
            className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-8"
          >
            {RIGHTS.map(right => {
              const IconComponent = right.icon;
              return (
                <motion.div
                  key={right.key}
                  variants={itemVariants}
                  whileHover={{ y: -5 }}
                  className="bg-white p-8 rounded-2xl shadow-lg border border-gray-100 hover:shadow-xl transition-all text-center"
                >
                  <div className="w-16 h-16 bg-brand-turquoise/10 rounded-full flex items-center justify-center mx-auto mb-4">
                    <IconComponent className="w-8 h-8 text-brand-turquoise" />
                  </div>
                  <h3 className="text-xl font-bold text-brand-navy mb-3">
                    {t(`rights.${right.key}.title`)}
                  </h3>
                  <p className="text-gray-600">{t(`rights.${right.key}.description`)}</p>
                </motion.div>
              );
            })}
          </motion.div>

          {/* Exercise Rights CTA */}
          <motion.div
            initial={{ opacity: 0, y: 30 }}
            animate={isContentInView ? { opacity: 1, y: 0 } : {}}
            transition={{ duration: 0.8, delay: 0.4 }}
            className="mt-12 text-center"
          >
            <p className="text-gray-600 mb-4">{t('rightsCta.text')}</p>
            <div className="flex flex-col sm:flex-row items-center justify-center space-y-4 sm:space-y-0 sm:space-x-4">
              <Link
                href="/login"
                className="px-6 py-3 bg-brand-turquoise text-white rounded-lg hover:bg-brand-turquoise/90 transition-colors font-medium"
              >
                {t('rightsCta.login')}
              </Link>
              <a
                href="mailto:dpo@xpeditis.com"
                className="px-6 py-3 bg-brand-navy text-white rounded-lg hover:bg-brand-navy/90 transition-colors font-medium"
              >
                {t('rightsCta.dpo')}
              </a>
            </div>
          </motion.div>
        </div>
      </section>

      {/* Principles */}
      <section className="py-20 bg-gray-50">
        <div className="max-w-7xl mx-auto px-6 lg:px-8">
          <motion.div
            initial={{ opacity: 0, y: 30 }}
            whileInView={{ opacity: 1, y: 0 }}
            viewport={{ once: true }}
            transition={{ duration: 0.8 }}
            className="text-center mb-16"
          >
            <h2 className="text-3xl lg:text-4xl font-bold text-brand-navy mb-4">
              {t('principlesTitle')}
            </h2>
            <p className="text-xl text-gray-600 max-w-2xl mx-auto">{t('principlesSubtitle')}</p>
          </motion.div>

          <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-8">
            {PRINCIPLES.map((principle, index) => {
              const IconComponent = principle.icon;
              return (
                <motion.div
                  key={principle.key}
                  initial={{ opacity: 0, scale: 0.9 }}
                  whileInView={{ opacity: 1, scale: 1 }}
                  viewport={{ once: true }}
                  transition={{ duration: 0.5, delay: index * 0.1 }}
                  className="bg-white p-6 rounded-2xl shadow-lg border border-gray-100"
                >
                  <div className="w-12 h-12 bg-brand-green/10 rounded-xl flex items-center justify-center mb-4">
                    <IconComponent className="w-6 h-6 text-brand-green" />
                  </div>
                  <h3 className="text-lg font-bold text-brand-navy mb-2">
                    {t(`principles.${principle.key}.title`)}
                  </h3>
                  <p className="text-gray-600 text-sm">
                    {t(`principles.${principle.key}.description`)}
                  </p>
                </motion.div>
              );
            })}
          </div>
        </div>
      </section>

      {/* Technical & Organizational Measures */}
      <section className="py-20">
        <div className="max-w-7xl mx-auto px-6 lg:px-8">
          <motion.div
            initial={{ opacity: 0, y: 30 }}
            whileInView={{ opacity: 1, y: 0 }}
            viewport={{ once: true }}
            transition={{ duration: 0.8 }}
            className="text-center mb-16"
          >
            <h2 className="text-3xl lg:text-4xl font-bold text-brand-navy mb-4">
              {t('measuresTitle')}
            </h2>
            <p className="text-xl text-gray-600 max-w-2xl mx-auto">{t('measuresSubtitle')}</p>
          </motion.div>

          <div className="grid grid-cols-1 md:grid-cols-2 gap-8">
            {MEASURES.map((key, index) => (
              <motion.div
                key={key}
                initial={{ opacity: 0, x: index === 0 ? -30 : 30 }}
                whileInView={{ opacity: 1, x: 0 }}
                viewport={{ once: true }}
                transition={{ duration: 0.6 }}
                className="bg-gradient-to-br from-brand-navy to-brand-navy/95 p-8 rounded-2xl"
              >
                <h3 className="text-xl font-bold text-white mb-6">{t(`measures.${key}.title`)}</h3>
                <ul className="space-y-4">
                  {MEASURE_ITEMS.map(itemKey => (
                    <li key={itemKey} className="flex items-center space-x-3 text-white/80">
                      <CheckCircle className="w-5 h-5 text-brand-turquoise flex-shrink-0" />
                      <span>{t(`measures.${key}.${itemKey}` as any)}</span>
                    </li>
                  ))}
                </ul>
              </motion.div>
            ))}
          </div>
        </div>
      </section>

      {/* Data Processing Register */}
      <section className="py-20 bg-gray-50">
        <div className="max-w-4xl mx-auto px-6 lg:px-8">
          <motion.div
            initial={{ opacity: 0, y: 30 }}
            whileInView={{ opacity: 1, y: 0 }}
            viewport={{ once: true }}
            transition={{ duration: 0.8 }}
            className="bg-white p-8 rounded-2xl shadow-lg border border-gray-100"
          >
            <div className="flex items-start space-x-4">
              <div className="w-12 h-12 bg-brand-turquoise/10 rounded-xl flex items-center justify-center flex-shrink-0">
                <FileText className="w-6 h-6 text-brand-turquoise" />
              </div>
              <div>
                <h3 className="text-2xl font-bold text-brand-navy mb-4">{t('register.title')}</h3>
                <p className="text-gray-600 mb-6">{t('register.body')}</p>
                <ul className="space-y-3 text-gray-600">
                  {REGISTER_ITEMS.map(itemKey => (
                    <li key={itemKey} className="flex items-center space-x-3">
                      <CheckCircle className="w-5 h-5 text-brand-green flex-shrink-0" />
                      <span>{t(`register.${itemKey}` as any)}</span>
                    </li>
                  ))}
                </ul>
              </div>
            </div>
          </motion.div>
        </div>
      </section>

      {/* Contact DPO */}
      <section className="py-20">
        <div className="max-w-4xl mx-auto px-6 lg:px-8">
          <motion.div
            initial={{ opacity: 0, y: 30 }}
            whileInView={{ opacity: 1, y: 0 }}
            viewport={{ once: true }}
            transition={{ duration: 0.8 }}
            className="bg-gradient-to-br from-brand-navy to-brand-navy/95 p-10 rounded-3xl text-center"
          >
            <UserCheck className="w-12 h-12 text-brand-turquoise mx-auto mb-4" />
            <h3 className="text-2xl font-bold text-white mb-4">{t('dpo.title')}</h3>
            <p className="text-white/80 mb-6 max-w-2xl mx-auto">{t('dpo.body')}</p>
            <div className="flex flex-col sm:flex-row items-center justify-center space-y-4 sm:space-y-0 sm:space-x-4">
              <a
                href="mailto:dpo@xpeditis.com"
                className="inline-flex items-center space-x-2 px-6 py-3 bg-brand-turquoise text-white rounded-lg hover:bg-brand-turquoise/90 transition-colors font-medium"
              >
                <Mail className="w-5 h-5" />
                <span>dpo@xpeditis.com</span>
              </a>
              <Link
                href="/privacy"
                className="px-6 py-3 bg-white text-brand-navy rounded-lg hover:bg-gray-100 transition-colors font-medium"
              >
                {t('dpo.privacyLink')}
              </Link>
            </div>
          </motion.div>
        </div>
      </section>

      <LandingFooter />
    </div>
  );
}
