'use client';

import { useEffect, useState } from 'react';
import { getTranslation, Language, useLanguage } from '@/lib/i18n';
import Link from 'next/link';
import { Target, Globe, Leaf, Users } from 'lucide-react';

const styles = `
  .about-hero {
    padding: 60px 20px;
    background: linear-gradient(to bottom right, rgb(20, 113, 76), transparent);
    text-align: center;
    color: #111827;
  }
  
  .dark .about-hero {
    color: #f3f4f6;
  }
  
  .about-hero h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: #111827;
  }
  
  .dark .about-hero h1 {
    color: #f3f4f6;
  }
  
  .about-hero p {
    font-size: 1.125rem;
    color: #6b7280;
  }
  
  .dark .about-hero p {
    color: #9ca3af;
  }
  
  .values-grid {
    max-width: 80rem;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    padding: 60px 20px;
    background-color: white;
  }
  
  .dark .values-grid {
    background-color: #111827;
  }
  
  .value-card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 18px;
    padding: 24px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  }
  
  .dark .value-card {
    background: #1f2937;
    border-color: #374151;
  }
  
  .value-card:hover {
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  }
  
  .value-icon {
    width: 48px;
    height: 48px;
    background: rgb(20, 113, 76);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
  }
  
  .value-card h3 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: #111827;
  }
  
  .dark .value-card h3 {
    color: #f3f4f6;
  }
  
  .value-card p {
    font-size: 0.875rem;
    color: #6b7280;
  }
  
  .dark .value-card p {
    color: #9ca3af;
  }
  
  .stats-section {
    padding: 60px 20px;
    background-color: #f9fafb;
  }
  
  .dark .stats-section {
    background-color: #0f1117;
  }
  
  .stats-container {
    max-width: 80rem;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 32px;
    text-align: center;
  }
  
  .stat {
    padding: 20px;
  }
  
  .stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: rgb(20, 113, 76);
    margin-bottom: 8px;
  }
  
  .stat-label {
    font-size: 0.875rem;
    color: #6b7280;
  }
  
  .dark .stat-label {
    color: #9ca3af;
  }
  
  .timeline-section {
    padding: 60px 20px;
    background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
  }
  
  .dark .timeline-section {
    background: linear-gradient(135deg, #111827 0%, #0f1117 100%);
  }
  
  .timeline-title {
    text-align: center;
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 48px;
    color: #111827;
  }
  
  .dark .timeline-title {
    color: #f3f4f6;
  }
  
  .timeline {
    max-width: 48rem;
    margin: 0 auto;
    position: relative;
  }
  
  .timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(180deg, rgb(20, 113, 76), rgb(20, 113, 76) 50%, transparent);
  }
  
  .timeline-item {
    display: flex;
    margin-bottom: 40px;
    position: relative;
    padding-left: 56px;
    animation: slideInLeft 0.6s ease-out forwards;
    opacity: 0;
  }
  
  .timeline-item:nth-child(1) { animation-delay: 0.1s; }
  .timeline-item:nth-child(2) { animation-delay: 0.2s; }
  .timeline-item:nth-child(3) { animation-delay: 0.3s; }
  .timeline-item:nth-child(4) { animation-delay: 0.4s; }
  .timeline-item:nth-child(5) { animation-delay: 0.5s; }
  
  @keyframes slideInLeft {
    from {
      opacity: 0;
      transform: translateX(-20px);
    }
    to {
      opacity: 1;
      transform: translateX(0);
    }
  }
  
  .timeline-dot {
    position: absolute;
    left: -4px;
    top: 8px;
    width: 24px;
    height: 24px;
    background: white;
    border-radius: 50%;
    border: 3px solid rgb(20, 113, 76);
    box-shadow: 0 0 0 2px rgb(20, 113, 76), 0 4px 12px rgba(20, 113, 76, 0.3);
    transition: all 0.3s ease;
  }
  
  .timeline-item:hover .timeline-dot {
    box-shadow: 0 0 0 2px rgb(20, 113, 76), 0 8px 24px rgba(20, 113, 76, 0.5);
    transform: scale(1.15);
  }
  
  .dark .timeline-dot {
    background: #1f2937;
  }
  
  .timeline-content {
    background: white;
    border-radius: 12px;
    padding: 20px 24px;
    border: 2px solid transparent;
    border-left: 4px solid rgb(20, 113, 76);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    flex: 1;
  }
  
  .timeline-item:hover .timeline-content {
    border-color: rgb(20, 113, 76);
    box-shadow: 0 8px 24px rgba(20, 113, 76, 0.15);
    transform: translateY(-4px);
  }
  
  .dark .timeline-content {
    background: #1f2937;
    border-left-color: rgb(20, 113, 76);
  }
  
  .timeline-year {
    font-weight: 700;
    color: rgb(20, 113, 76);
    font-size: 1.125rem;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  
  .timeline-year::before {
    content: '📅';
  }
  
  .timeline-event {
    color: #6b7280;
    margin-top: 8px;
    font-size: 0.95rem;
    font-weight: 500;
  }
  
  .dark .timeline-event {
    color: #d1d5db;
  }
  
  .cta-blue {
    background-color: rgb(20, 113, 76);
    color: white;
    padding: 60px 20px;
    text-align: center;
  }
  
  .cta-blue h2 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 16px;
  }
  
  .cta-blue p {
    font-size: 1.125rem;
    margin-bottom: 32px;
    max-width: 42rem;
    margin-left: auto;
    margin-right: auto;
  }
  
  .button-white {
    display: inline-block;
    padding: 16px 32px;
    background-color: white;
    color: rgb(20, 113, 76);
    font-weight: 700;
    border-radius: 12px;
    text-decoration: none;
    transition: all 0.2s;
  }
  
  .button-white:hover {
    transform: scale(1.05);
  }
  
  @media (max-width: 768px) {
    .values-grid {
      grid-template-columns: 1fr;
    }
    
    .about-hero h1 {
      font-size: 1.875rem;
    }
  }
`;

export default function About() {
  const [lang, setLang] = useState<Language>('en');
  const { getLang } = useLanguage();
  const t = (key: string) => getTranslation(lang, key);

  useEffect(() => {
    setLang(getLang());
    const handleLanguageChange = (e: any) => setLang(e.detail);
    window.addEventListener('languageChange', handleLanguageChange);
    return () => window.removeEventListener('languageChange', handleLanguageChange);
  }, [getLang]);

  const values = [
    { icon: Target, title: t('about.mission'), desc: t('about.missionText') },
    { icon: Globe, title: t('about.network'), desc: t('about.networkText') },
    { icon: Users, title: t('about.comfort'), desc: t('about.comfortText') },
    { icon: Leaf, title: t('about.eco'), desc: t('about.ecoText') },
  ];

  return (
    <>
      <style>{styles}</style>
      <main>
        <section className="about-hero">
          <h1>{t('about.title')}</h1>
          <p>{t('about.subtitle')}</p>
        </section>

        <section className="values-grid">
          {values.map((value, idx) => {
            const Icon = value.icon;
            return (
              <div key={idx} className="value-card">
                <div className="value-icon">
                  <Icon size={24} color="white" />
                </div>
                <h3>{value.title}</h3>
                <p>{value.desc}</p>
              </div>
            );
          })}
        </section>

        <section className="stats-section">
          <div className="stats-container">
            <div className="stat">
              <div className="stat-number">21</div>
              <div className="stat-label">Railway Stations</div>
            </div>
            <div className="stat">
              <div className="stat-number">360+</div>
              <div className="stat-label">Comfortable Seats</div>
            </div>
            <div className="stat">
              <div className="stat-number">3</div>
              <div className="stat-label">Seat Classes</div>
            </div>
            <div className="stat">
              <div className="stat-number">24/7</div>
              <div className="stat-label">Customer Support</div>
            </div>
          </div>
        </section>

        <section className="timeline-section">
          <h2 className="timeline-title">Our Journey</h2>
          <div className="timeline">
            {[
              { year: '2020', event: 'EDR Platform Launched' },
              { year: '2021', event: 'Reached 10,000+ Passengers' },
              { year: '2022', event: 'Introduced Multi-Currency Support' },
              { year: '2023', event: 'Launched Loyalty Program' },
              { year: '2024', event: 'Age-Based Pricing & Verifayda Integration' },
            ].map((item, idx) => (
              <div key={idx} className="timeline-item">
                <div className="timeline-dot" />
                <div className="timeline-content">
                  <div className="timeline-year">{item.year}</div>
                  <div className="timeline-event">{item.event}</div>
                </div>
              </div>
            ))}
          </div>
        </section>

        <section className="cta-blue">
          <h2>Join Our Community</h2>
          <p>Be part of the modern railway revolution in East Africa.</p>
          <Link href="/booking/search" className="button-white">Book Your First Journey</Link>
        </section>
      </main>
    </>
  );
}
