"use client";

import { useState, useEffect, useCallback, useRef } from "react";
import Image from "next/image";
import { LordIcon } from "@/components/LordIcon";
import { MauritaniaMap } from "@/components/MauritaniaMap";
import { ProjectsCarousel } from "@/components/ProjectsCarousel";
import { EditableSection } from "@/components/admin/EditableSection";
import { useEditMode } from "@/context/EditModeContext";
import { ArrowRight, ChevronLeft, ChevronRight, Handshake, TrendingUp, Play } from "lucide-react";

const HERO_SLIDES = [
  { src: "/carousel-images/1.jpg", alt: "ANED - Actions sur le terrain" },
  { src: "/carousel-images/3.jpeg", alt: "ANED - Communautés bénéficiaires" },
  { src: "/carousel-images/4.jpeg", alt: "ANED - Communautés bénéficiaires" },
  { src: "/carousel-images/8.jpeg", alt: "ANED - Nutrition et développement" },
  { src: "/carousel-images/7.jpeg", alt: "ANED - Activités sur le terrain" },
  { src: "/carousel-images/9.jpeg", alt: "ANED - Projets communautaires" },
];

// LordIcon URLs and colors are fixed visuals per position — content comes from DB
const VALUE_LORD_ICONS = [
  { src: "https://cdn.lordicon.com/gqdnbnwt.json", color: "#E67E22" },
  { src: "https://cdn.lordicon.com/fhtaantg.json", color: "#4A7C59" },
  { src: "https://cdn.lordicon.com/egiwmiit.json", color: "#1E40AF" },
  { src: "https://cdn.lordicon.com/dxjqoygy.json", color: "#27AE60" },
];

function renderHighlighted(text: string) {
  const parts = text.split(/(\*\*[^*]+\*\*)/g);
  return parts.map((part, i) => {
    if (part.startsWith("**") && part.endsWith("**")) {
      return <span key={i} className="text-[#FCBF49]">{part.slice(2, -2)}</span>;
    }
    return <span key={i}>{part}</span>;
  });
}

type AboutContent = {
  title: string;
  description: string;
  stat1Value: string;
  stat1Label: string;
  stat2Value: string;
  stat2Label: string;
  stat3Value: string;
  stat3Label: string;
};

type CoreValue = {
  id: string;
  number: string;
  name: string;
  description: string;
  color: string;
  order: number;
};

type SiteSettings = {
  heroTitle: string;
  heroSubtitle: string;
  heroCta1Text: string;
  heroCta1Link: string;
  heroCta2Text: string;
  heroCta2Link: string;
  mapStat1: string; mapStat1Label: string;
  mapStat2: string; mapStat2Label: string;
  mapStat3: string; mapStat3Label: string;
  mapStat4: string; mapStat4Label: string;
  partnersSectionTitle: string;
  partnersSectionSubtitle: string;
  networkBadge1: string;
  networkBadge2: string;
  presidentQuote: string;
  bottomCtaTitle: string;
  bottomCtaDescription: string;
  bottomStat1: string; bottomStat1Label: string;
  bottomStat2: string; bottomStat2Label: string;
  bottomStat3: string; bottomStat3Label: string;
};

type Partner = {
  id: string;
  name: string;
  logo: string;
  category: string;
};

type Campaign = {
  id: string;
  title: string;
  slogan: string | null;
  description: string | null;
  amountRaised: string | null;
  mediaType: string;
  imageUrl: string | null;
  videoUrl: string | null;
  active: boolean;
};

const ABOUT_DEFAULTS: AboutContent = {
  title: "Qui sommes-nous ?",
  description: "Nous sommes une organisation nationale et pionnière dans les domaines du développement et de l'humanitaire.",
  stat1Value: "20+", stat1Label: "Années",
  stat2Value: "7", stat2Label: "Zones",
  stat3Value: "20+", stat3Label: "Partenaires",
};

const SETTINGS_DEFAULTS: SiteSettings = {
  heroTitle: "Ensemble contre la **malnutrition** pour un meilleur développement",
  heroSubtitle: "Afin que chaque enfant, chaque femme et chaque ménage sécurise sa situation alimentaire et nutritionnelle de manière **durable**.",
  heroCta1Text: "Découvrir ANED", heroCta1Link: "#mission",
  heroCta2Text: "Nos projets", heroCta2Link: "#projets",
  mapStat1: "20+", mapStat1Label: "années d'expérience",
  mapStat2: "7", mapStat2Label: "wilayas prioritaires",
  mapStat3: "50K+", mapStat3Label: "bénéficiaires",
  mapStat4: "15+", mapStat4Label: "projets réalisés",
  partnersSectionTitle: "Nos partenaires",
  partnersSectionSubtitle: "20+ années de collaborations avec les acteurs majeurs du développement et de l'aide humanitaire.",
  networkBadge1: "ROSA · Lead Nutrition Mauritanie",
  networkBadge2: "Initiative SUN",
  presidentQuote: "Ce site Web se veut une vitrine qui met en exergue nos différentes interventions, nos partenaires et les personnes pour lesquelles et avec lesquelles nous travaillons.",
  bottomCtaTitle: "Ensemble, construisons un avenir sans malnutrition",
  bottomCtaDescription: "Depuis 2002, ANED protège les enfants et les familles vulnérables de Mauritanie. Chaque partenariat compte.",
  bottomStat1: "20+", bottomStat1Label: "ans d'expérience",
  bottomStat2: "50K+", bottomStat2Label: "bénéficiaires",
  bottomStat3: "7", bottomStat3Label: "wilayas couvertes",
};

function toEmbedUrl(url: string): string {
  try {
    const ytMatch = url.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([A-Za-z0-9_-]{11})/);
    if (ytMatch) return `https://www.youtube.com/embed/${ytMatch[1]}`;
    const vimeoMatch = url.match(/vimeo\.com\/(\d+)/);
    if (vimeoMatch) return `https://player.vimeo.com/video/${vimeoMatch[1]}`;
  } catch { /* ignore */ }
  return url;
}

function HeroCarousel({ about, settings }: { about: AboutContent; settings: SiteSettings }) {
  const [current, setCurrent] = useState(0);
  const [transitioning, setTransitioning] = useState(false);
  const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);

  const goTo = useCallback((index: number) => {
    if (transitioning) return;
    setTransitioning(true);
    setTimeout(() => { setCurrent(index); setTransitioning(false); }, 300);
  }, [transitioning]);

  const prev = useCallback(() => goTo((current - 1 + HERO_SLIDES.length) % HERO_SLIDES.length), [current, goTo]);
  const next = useCallback(() => goTo((current + 1) % HERO_SLIDES.length), [current, goTo]);

  useEffect(() => {
    timerRef.current = setTimeout(() => { setCurrent((c) => (c + 1) % HERO_SLIDES.length); }, 5000);
    return () => { if (timerRef.current) clearTimeout(timerRef.current); };
  }, [current]);

  return (
    <section className="relative min-h-[80vh] sm:min-h-[88vh] flex items-end">
      <div className="absolute inset-0 overflow-hidden">
        {HERO_SLIDES.map((slide, i) => (
          <div key={slide.src} className={`absolute inset-0 transition-opacity duration-700 ${i === current ? "opacity-100 z-10" : "opacity-0 z-0"}`}>
            <Image src={slide.src} alt={slide.alt} fill priority={i === 0} quality={90} className="object-cover object-center" sizes="100vw" />
            <div className="absolute inset-0 bg-gradient-to-t from-black/80 via-black/20 to-transparent" />
          </div>
        ))}
      </div>

      <div className="relative z-20 w-full pb-10 sm:pb-14 lg:pb-16">
        <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
          <div className="max-w-4xl space-y-4 sm:space-y-6">
            <h1 className="font-serif text-4xl sm:text-5xl md:text-6xl lg:text-7xl font-black leading-[1.1] text-white drop-shadow-2xl">
              {renderHighlighted(settings.heroTitle)}
            </h1>
            <p className="text-base sm:text-lg md:text-xl leading-relaxed text-white/95 drop-shadow-lg font-light max-w-3xl">
              {renderHighlighted(settings.heroSubtitle)}
            </p>
            <div className="flex flex-col lg:flex-row lg:items-center lg:justify-between gap-6 pt-4">
              <div className="flex gap-6 sm:gap-8">
                <div>
                  <div className="font-serif text-3xl sm:text-4xl font-black text-[#FCBF49] drop-shadow-lg">{about.stat1Value}</div>
                  <div className="text-xs sm:text-sm text-white/90 drop-shadow-md">{about.stat1Label}</div>
                </div>
                <div className="border-l border-white/30 pl-6 sm:pl-8">
                  <div className="font-serif text-3xl sm:text-4xl font-black text-[#FCBF49] drop-shadow-lg">{about.stat2Value}</div>
                  <div className="text-xs sm:text-sm text-white/90 drop-shadow-md">{about.stat2Label}</div>
                </div>
                <div className="border-l border-white/30 pl-6 sm:pl-8">
                  <div className="font-serif text-3xl sm:text-4xl font-black text-[#FCBF49] drop-shadow-lg">{about.stat3Value}</div>
                  <div className="text-xs sm:text-sm text-white/90 drop-shadow-md">{about.stat3Label}</div>
                </div>
              </div>
              <div className="flex flex-col sm:flex-row gap-3 sm:gap-4">
                <a href={settings.heroCta1Link} className="bg-white hover:bg-gray-50 text-[#0047AB] px-6 sm:px-8 py-3 sm:py-3.5 rounded-full font-semibold transition-all hover:shadow-2xl flex items-center justify-center gap-2 text-sm sm:text-base group">
                  {settings.heroCta1Text}
                  <ArrowRight className="w-4 h-4 group-hover:translate-x-1 transition-transform" />
                </a>
                <a href={settings.heroCta2Link} className="border-2 border-white text-white hover:bg-white hover:text-[#0047AB] px-6 sm:px-8 py-3 sm:py-3.5 rounded-full font-semibold transition-all hover:shadow-2xl flex items-center justify-center gap-2 text-sm sm:text-base group backdrop-blur-sm">
                  {settings.heroCta2Text}
                  <ArrowRight className="w-4 h-4 group-hover:translate-x-1 transition-transform" />
                </a>
              </div>
            </div>
          </div>
        </div>
      </div>

      <button onClick={prev} aria-label="Image précédente" className="absolute left-3 sm:left-5 top-1/2 -translate-y-1/2 z-30 w-9 h-9 sm:w-11 sm:h-11 rounded-full bg-black/30 hover:bg-black/50 text-white flex items-center justify-center backdrop-blur-sm transition-all hover:scale-110">
        <ChevronLeft size={20} />
      </button>
      <button onClick={next} aria-label="Image suivante" className="absolute right-3 sm:right-5 top-1/2 -translate-y-1/2 z-30 w-9 h-9 sm:w-11 sm:h-11 rounded-full bg-black/30 hover:bg-black/50 text-white flex items-center justify-center backdrop-blur-sm transition-all hover:scale-110">
        <ChevronRight size={20} />
      </button>

      <div className="absolute bottom-4 left-1/2 -translate-x-1/2 z-30 flex gap-2">
        {HERO_SLIDES.map((_, i) => (
          <button key={i} onClick={() => goTo(i)} aria-label={`Aller à l'image ${i + 1}`} className={`rounded-full transition-all duration-300 ${i === current ? "w-6 h-2 bg-white" : "w-2 h-2 bg-white/50 hover:bg-white/80"}`} />
        ))}
      </div>
    </section>
  );
}

export default function Home() {
  const [partners, setPartners] = useState<Partner[]>([]);
  const [campaign, setCampaign] = useState<Campaign | null>(null);
  const [about, setAbout] = useState<AboutContent>(ABOUT_DEFAULTS);
  const [settings, setSettings] = useState<SiteSettings>(SETTINGS_DEFAULTS);
  const [coreValues, setCoreValues] = useState<CoreValue[]>([]);
  const { contentVersion } = useEditMode();

  useEffect(() => {
    fetch("/api/partners").then((r) => r.json()).then(setPartners).catch(console.error);
    fetch("/api/campaign").then((r) => r.json()).then(setCampaign).catch(console.error);
    fetch("/api/about").then((r) => r.json()).then((d) => setAbout({ ...ABOUT_DEFAULTS, ...d })).catch(console.error);
    fetch("/api/site-settings").then((r) => r.json()).then((d) => setSettings({ ...SETTINGS_DEFAULTS, ...d })).catch(console.error);
    fetch("/api/core-values").then((r) => r.json()).then(setCoreValues).catch(console.error);
  }, [contentVersion]);

  return (
    <>
      {/* Campaign Banner */}
      {campaign && (
        <>
          <style>{`
            @keyframes banner-shimmer {
              0%   { transform: translateX(-200%) skewX(-20deg); opacity: 0; }
              15%  { opacity: 1; }
              85%  { opacity: 1; }
              100% { transform: translateX(800%) skewX(-20deg); opacity: 0; }
            }
            .banner-shimmer { animation: banner-shimmer 4.5s cubic-bezier(0.4,0,0.6,1) infinite; animation-delay: 1.8s; }
          `}</style>

          <a href={`/campagne/${campaign.id}`} className="group relative flex items-center overflow-hidden border-b border-black/10 cursor-pointer">
            <div className="absolute inset-0 bg-gradient-to-r from-[#C96210] via-[#E67E22] to-[#D4700F] group-hover:from-[#D46A12] group-hover:via-[#F08030] group-hover:to-[#D97012] transition-colors duration-500" />
            <div className="banner-shimmer absolute inset-y-0 w-14 bg-gradient-to-r from-transparent via-white/[0.14] to-transparent pointer-events-none" />
            <div className="pointer-events-none absolute right-0 inset-y-0 w-24 bg-gradient-to-l from-[#C96210]/50 to-transparent z-10" />

            <div className="relative z-20 flex items-center w-full max-w-7xl mx-auto px-5 sm:px-6 lg:px-8 py-1.5 sm:py-2 gap-3 sm:gap-4">
              <div className="flex-shrink-0 flex items-center gap-2 bg-white/20 border border-white/30 rounded-full px-2.5 py-1 group-hover:bg-white/30 transition-all duration-300">
                <span className="relative flex h-2 w-2 flex-shrink-0">
                  <span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-white opacity-80" />
                  <span className="relative inline-flex rounded-full h-2 w-2 bg-white" />
                </span>
                <span className="hidden sm:block text-white text-[10px] font-extrabold uppercase tracking-widest whitespace-nowrap">En cours</span>
              </div>
              <div className="hidden sm:block h-5 w-px bg-white/25 flex-shrink-0" />
              <div className="flex-1 min-w-0">
                <span className="block text-white font-bold text-sm sm:text-[15px] truncate leading-snug drop-shadow-sm">{campaign.title}</span>
                {campaign.slogan && <span className="block sm:hidden text-white/70 text-[11px] truncate mt-0.5">{campaign.slogan}</span>}
              </div>
              {campaign.slogan && (
                <span className="hidden lg:flex items-center gap-2 text-white/70 text-sm min-w-0 flex-shrink-0 max-w-[260px]">
                  <span className="w-1 h-1 rounded-full bg-white/30 flex-shrink-0" />
                  <span className="truncate">{campaign.slogan}</span>
                </span>
              )}
              {campaign.amountRaised && (
                <div className="hidden md:flex items-center gap-1.5 bg-white/20 border border-white/25 text-white text-xs font-bold rounded-full px-3 py-1 flex-shrink-0 whitespace-nowrap group-hover:bg-white/30 transition-all duration-300">
                  <TrendingUp size={11} />
                  {campaign.amountRaised}
                </div>
              )}
              {(campaign.imageUrl || campaign.videoUrl) && (
                <div className="relative w-14 h-9 sm:w-20 sm:h-12 rounded-lg sm:rounded-xl overflow-hidden flex-shrink-0 ring-2 ring-white/25 group-hover:ring-white/60 group-hover:shadow-[0_0_16px_rgba(0,0,0,0.25)] transition-all duration-300 bg-black/20">
                  {(() => {
                    if (campaign.mediaType === "video" && campaign.videoUrl) {
                      const ytMatch = campaign.videoUrl.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([A-Za-z0-9_-]{11})/);
                      if (ytMatch) {
                        /* eslint-disable-next-line @next/next/no-img-element */
                        return <img src={`https://img.youtube.com/vi/${ytMatch[1]}/mqdefault.jpg`} alt="" className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500" />;
                      }
                      const posterUrl = campaign.videoUrl.replace(/\.[^/.]+$/, ".jpg");
                      return (
                        <div className="relative w-full h-full">
                          {/* eslint-disable-next-line @next/next/no-img-element */}
                          <img src={posterUrl} alt="" className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500" />
                          <div className="absolute inset-0 flex items-center justify-center">
                            <div className="w-6 h-6 rounded-full bg-black/40 flex items-center justify-center">
                              <Play size={10} className="text-white ml-0.5" />
                            </div>
                          </div>
                        </div>
                      );
                    }
                    if (campaign.imageUrl) {
                      /* eslint-disable-next-line @next/next/no-img-element */
                      return <img src={campaign.imageUrl} alt="" className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500" />;
                    }
                    return null;
                  })()}
                  <div className="absolute inset-0 bg-black/15 group-hover:bg-black/0 transition-colors duration-300" />
                </div>
              )}
              <div className="flex-shrink-0 flex items-center gap-1.5 bg-[#0E1A10] group-hover:bg-[#1a3a1f] text-white text-[11px] sm:text-xs font-bold uppercase tracking-wide rounded-full px-3 sm:px-4 py-2 transition-all duration-200 shadow-[0_2px_8px_rgba(0,0,0,0.25)] group-hover:shadow-[0_4px_16px_rgba(0,0,0,0.35)]">
                <span className="hidden sm:inline whitespace-nowrap">Voir la campagne</span>
                <ArrowRight size={13} className="group-hover:translate-x-0.5 transition-transform duration-200" />
              </div>
            </div>
          </a>
        </>
      )}

      {/* Hero Carousel */}
      <EditableSection sectionId="hero" label="Texte du héros">
        <HeroCarousel about={about} settings={settings} />
      </EditableSection>

      {/* Mission Statement */}
      <EditableSection sectionId="about" label="Section Mission (qui sommes-nous)">
      <section id="mission" className="py-12 sm:py-16 lg:py-20 bg-gradient-to-b from-white to-gray-50 min-h-screen flex items-center">
        <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 w-full">
          <div className="max-w-5xl mx-auto text-center space-y-6 sm:space-y-8">
            <div className="inline-block">
              <LordIcon src="https://cdn.lordicon.com/fpmskzsv.json" trigger="loop" delay="2000" colors="primary:#4A7C59,secondary:#E67E22" style={{width: "64px", height: "64px"}} />
            </div>

            <h2 className="font-serif text-3xl sm:text-4xl lg:text-5xl font-black text-[#2C3E50]">{about.title}</h2>

            <p className="text-base sm:text-lg lg:text-xl text-gray-700 leading-relaxed max-w-4xl mx-auto px-4 whitespace-pre-line">{about.description}</p>

            <div className="grid grid-cols-2 lg:grid-cols-4 gap-3 sm:gap-4 lg:gap-6 pt-6 sm:pt-8 max-w-6xl mx-auto">
              {coreValues.slice(0, 4).map((v, i) => {
                const icon = VALUE_LORD_ICONS[i] ?? VALUE_LORD_ICONS[0];
                return (
                  <div key={v.id} className="group hover:scale-105 transition-all duration-300">
                    <div className="bg-linear-to-br from-white to-white p-4 sm:p-6 rounded-xl sm:rounded-2xl border-2 hover:shadow-xl transition-all h-full flex flex-col items-center justify-center text-center"
                      style={{ borderColor: `${icon.color}33`, backgroundColor: `${icon.color}10` }}
                      onMouseEnter={(e) => (e.currentTarget.style.borderColor = icon.color)}
                      onMouseLeave={(e) => (e.currentTarget.style.borderColor = `${icon.color}33`)}
                    >
                      <LordIcon src={icon.src} trigger="hover" colors={`primary:${icon.color}`} style={{width: "48px", height: "48px"}} />
                      <h3 className="font-bold text-sm sm:text-base lg:text-lg text-[#2C3E50] mt-3">{v.name}</h3>
                    </div>
                  </div>
                );
              })}
            </div>
          </div>
        </div>
      </section>
      </EditableSection>

      {/* Mot de la Présidente — teaser */}
      <EditableSection sectionId="president-quote" label="Citation de la Présidente">
      <section id="president" className="py-16 bg-[#0E1A10]">
        <div className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8">
          <div className="flex flex-col items-center gap-8 sm:gap-12">
            <div className="flex-1 text-center sm:text-left w-full">
              <p className="text-xs font-semibold text-[#6DBF87] uppercase tracking-widest mb-3">Mot de la Présidente</p>
              <div className="font-serif text-4xl leading-none text-[#4A7C59]/30 select-none mb-1">&ldquo;</div>
              <p className="text-gray-300 text-base sm:text-lg leading-relaxed mb-5 italic">{settings.presidentQuote}</p>
              <div className="flex flex-col sm:flex-row items-center sm:items-end justify-between gap-4">
                <p className="text-white/60 text-sm">— La Présidente, ANED</p>
                <a href="/mot-de-la-presidente" className="inline-flex items-center gap-2 bg-[#4A7C59] hover:bg-[#3d6849] text-white text-sm font-semibold px-5 py-2.5 rounded-lg transition-colors">
                  Lire le message complet
                  <ArrowRight size={15} />
                </a>
              </div>
            </div>
          </div>
        </div>
      </section>
      </EditableSection>

      {/* Interactive Map - Notre Impact */}
      <EditableSection sectionId="map-stats" label="Carte — statistiques">
      <section id="impact" className="py-10 sm:py-14 bg-white border-t border-b border-gray-200">
        <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 w-full">
          <div className="grid grid-cols-1 lg:grid-cols-2 gap-8 lg:gap-12 items-center">
            <div>
              <div className="mb-4">
                <LordIcon src="https://cdn.lordicon.com/slmechys.json" trigger="loop" delay="2000" colors="primary:#4A7C59,secondary:#E67E22" style={{width: "48px", height: "48px"}} />
              </div>
              <h2 className="font-serif text-3xl sm:text-4xl font-black text-[#2C3E50] mb-3 leading-tight">
                Notre impact<br className="hidden sm:block" /> en Mauritanie
              </h2>
              <p className="text-sm sm:text-base text-gray-600 mb-6">
                {settings.mapStat1} {settings.mapStat1Label} dans {settings.mapStat2} wilayas prioritaires
              </p>

              <div className="grid grid-cols-2 gap-3 mb-6">
                {[
                  { value: settings.mapStat1, label: settings.mapStat1Label },
                  { value: settings.mapStat2, label: settings.mapStat2Label },
                  { value: settings.mapStat3, label: settings.mapStat3Label },
                  { value: settings.mapStat4, label: settings.mapStat4Label },
                ].map((stat) => (
                  <div key={stat.label} className="bg-gray-50 rounded-lg p-3 border border-gray-100">
                    <div className="font-serif text-2xl font-black text-[#4A7C59]">{stat.value}</div>
                    <div className="text-xs text-gray-500 mt-0.5">{stat.label}</div>
                  </div>
                ))}
              </div>

              <div className="space-y-2 mb-4">
                <p className="text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2">Légende</p>
                {[
                  { color: "#C8DFD0", label: "Zone prioritaire", border: "#4A7C59" },
                  { color: "#D5D8DC", label: "Zone de relation", border: "#7F8C8D" },
                  { color: "#EAECEE", label: "Non couvert", border: "#BDC3C7" },
                ].map((item) => (
                  <div key={item.label} className="flex items-center gap-2 text-sm text-gray-700">
                    <div className="w-4 h-4 rounded flex-shrink-0 border" style={{ backgroundColor: item.color, borderColor: item.border }} />
                    <span>{item.label}</span>
                  </div>
                ))}
              </div>

              <p className="text-xs text-gray-400 italic">Survolez une wilaya pour voir les interventions</p>
            </div>

            <div><MauritaniaMap /></div>
          </div>
        </div>
      </section>
      </EditableSection>

      <ProjectsCarousel />

      {/* Partners Section */}
      <EditableSection sectionId="partners-header" label="Section partenaires">
      <section id="partenaires" className="py-16 bg-white border-t border-gray-100">
        <div className="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
          <div className="flex flex-col sm:flex-row sm:items-end justify-between gap-6 mb-12">
            <div>
              <p className="text-xs font-semibold text-[#4A7C59] uppercase tracking-widest mb-2 flex items-center gap-1.5">
                <Handshake size={13} />
                Partenariats
              </p>
              <h2 className="font-serif text-4xl md:text-5xl font-black text-[#2C3E50]">{settings.partnersSectionTitle}</h2>
            </div>
            <p className="text-sm text-gray-400 max-w-xs leading-relaxed">{settings.partnersSectionSubtitle}</p>
          </div>

          <div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-4 mb-10">
            {partners.length > 0 ? (
              partners.map((p) => (
                <div key={p.id} title={p.name} className="group flex items-center justify-center h-28 rounded-xl border border-gray-100 hover:border-gray-200 hover:shadow-sm bg-white transition-all duration-300 p-5">
                  {/* eslint-disable-next-line @next/next/no-img-element */}
                  <img src={p.logo} alt={p.name} className="max-h-16 max-w-full w-auto object-contain opacity-100 md:grayscale md:opacity-40 md:group-hover:grayscale-0 md:group-hover:opacity-100 transition-all duration-300" />
                </div>
              ))
            ) : (
              <div className="col-span-full text-center py-8 text-gray-400">Chargement des partenaires...</div>
            )}
          </div>

          <div className="border-t border-gray-100 pt-7 flex flex-col sm:flex-row sm:items-center gap-3">
            <span className="text-[11px] font-semibold text-gray-400 uppercase tracking-wider whitespace-nowrap">Membre actif de</span>
            <div className="flex flex-wrap gap-2">
              {settings.networkBadge1 && (
                <span className="text-sm text-gray-600 border border-gray-200 px-3 py-1.5 rounded-lg bg-gray-50 font-medium">{settings.networkBadge1}</span>
              )}
              {settings.networkBadge2 && (
                <span className="text-sm text-gray-600 border border-gray-200 px-3 py-1.5 rounded-lg bg-gray-50 font-medium">{settings.networkBadge2}</span>
              )}
            </div>
          </div>
        </div>
      </section>
      </EditableSection>

      {/* CTA */}
      <EditableSection sectionId="bottom-cta" label="Appel à l'action (bas de page)">
      <section className="py-24 bg-[#0E1A10]">
        <div className="max-w-3xl mx-auto px-4 sm:px-6 lg:px-8 text-center">
          <p className="text-xs font-semibold text-[#6DBF87] uppercase tracking-widest mb-5">Rejoignez notre mission</p>

          <h2 className="font-serif text-4xl sm:text-5xl lg:text-6xl font-black text-white leading-tight mb-6">
            {settings.bottomCtaTitle}
          </h2>

          <p className="text-gray-400 text-base sm:text-lg max-w-xl mx-auto mb-10 leading-relaxed">
            {settings.bottomCtaDescription}
          </p>

          <div className="flex flex-col sm:flex-row gap-3 justify-center">
            <a href="/contact" className="bg-[#4A7C59] hover:bg-[#3d6849] text-white px-8 py-3.5 rounded-lg font-semibold flex items-center justify-center gap-2 text-sm transition-colors">
              Nous contacter <ArrowRight size={15} />
            </a>
            <a href="/projets" className="border border-white/15 hover:border-white/40 hover:bg-white/5 text-white px-8 py-3.5 rounded-lg font-semibold transition-all flex items-center justify-center gap-2 text-sm">
              Nos projets <ArrowRight size={15} />
            </a>
          </div>

          <div className="mt-16 grid grid-cols-3 gap-6 border-t border-white/8 pt-12">
            {[
              { value: settings.bottomStat1, label: settings.bottomStat1Label },
              { value: settings.bottomStat2, label: settings.bottomStat2Label },
              { value: settings.bottomStat3, label: settings.bottomStat3Label },
            ].map((s) => (
              <div key={s.label}>
                <div className="font-serif text-3xl font-black text-white mb-1">{s.value}</div>
                <div className="text-xs text-gray-500 uppercase tracking-wide">{s.label}</div>
              </div>
            ))}
          </div>
        </div>
      </section>
      </EditableSection>
    </>
  );
}
