import Image from "next/image";
import { ExternalLink } from "lucide-react";
import { cn } from "@/lib/utils";
import { programAxes } from "./programAxesData";

export default function Programme() {
  return (
    <div className="flex flex-col gap-16 w-full">
      {/* Programme */}
      <section className="w-full flex flex-col gap-6 py-1">
        <div>
          <h1 className="text-2xl md:text-3xl font-semibold leading-10 tracking-tight text-black dark:text-zinc-50 mb-4">
            PROGRAMME
          </h1>
        </div>
        <div className="flex flex-col gap-12">
         {programAxes.map((axis) => (
           <section
             key={axis.id}
            className={cn(
               "bg-white rounded-2xl shadow-lg overflow-hidden transition-all duration-300 hover:shadow-2xl",
               "border-t-4 border-b-4 border-l-0 md:border-t-0 md:border-b-0 md:border-l-4",
               axis.borderColorClass
            )}
          >
            {/* En-tête — sur mobile : logo + barre + titre centrés ; sur desktop : logo à gauche, barre verticale + titre */}
            <div className="p-4 md:p-8 lg:p-12">
              <div className="flex flex-col items-center text-center md:flex-row md:items-start md:text-left gap-4 md:gap-6 lg:gap-8">
                {/* Logo */}
                <div className="shrink-0 w-12 h-12 md:w-[100px] md:h-[100px]">
                  <Image
                    src="/icon_prioleaud2026.svg"
                    alt="Logo Prioleaud 2026"
                    width={100}
                    height={100}
                    className="object-contain w-full h-full"
                  />
                </div>

                {/* Titre et description */}
                <div className="flex-1 min-w-0 w-full">
                  {/* Sur mobile : barre horizontale centrée + titre ; sur desktop : barre verticale à gauche + titre */}
                  <div className="flex flex-col items-center md:flex-row md:items-center gap-2 md:gap-3 mb-4">
                    <div
                      className="w-16 h-1 md:w-1 md:h-12 rounded-full shrink-0"
                      style={{ backgroundColor: axis.color }}
                    />
                    <h2
                      className={cn(
                        "text-xl md:text-3xl lg:text-4xl font-bold",
                        axis.colorClass
                      )}
                    >
                      {axis.title}
                    </h2>
                  </div>
                  <p className="text-lg leading-7 text-zinc-700 dark:text-zinc-300 max-w-3xl text-justify md:text-left">
                    {axis.description}
                  </p>
                </div>
              </div>
            </div>

           {/* Idées */}
            <div className="p-8 lg:p-12 pt-0">
             <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
                {axis.ideas.map((content, index) => {
                  const number = index + 1;
                  return (
                    <div
                      key={index}
                      className={cn(
                        "bg-white rounded-xl overflow-hidden border transition-all duration-300 hover:shadow-xl",
                        "hover:-translate-y-1",
                        axis.borderColorClass
                      )}
                    >
                      <div className="p-6 flex flex-col items-center md:flex-row md:items-start gap-4">
                        <div
                          className="shrink-0 w-12 h-12 rounded-full flex items-center justify-center text-white font-bold text-lg"
                          style={{ backgroundColor: axis.color }}
                        >
                          {number}
                        </div>
                        <p className="text-zinc-600 dark:text-zinc-400 leading-7 flex-1 min-w-0 w-full">
                          {content}
                        </p>
                      </div>
                    </div>
                  );
                })}
              </div>
            </div>
          </section>
        ))}
        </div>
      </section>
       {/* Bilan de mandat en premier */}
       <section className="w-full py-1">
        <div className="flex flex-col gap-16 w-full">
          <h2 className="text-2xl md:text-3xl font-semibold leading-10 tracking-tight text-black dark:text-zinc-50 mb-4">
            BILAN DE MANDAT
          </h2>
        </div>

        {/* Affichage du PDF */}
        <div className="bg-white rounded-2xl shadow-lg overflow-hidden border border-zinc-200">
          {/* Version mobile : bouton pour ouvrir le PDF */}
          <div className="block md:hidden p-6">
            <a
              href="/BilanMandat.pdf"
              target="_blank"
              rel="noopener noreferrer"
              className="flex items-center justify-center gap-3 w-full px-6 py-4 bg-orange text-white rounded-lg font-semibold hover:bg-orange/90 transition-colors shadow-md"
            >
              <ExternalLink size={20} />
              <span>Ouvrir le bilan de mandat</span>
            </a>
            <p className="text-sm text-zinc-600 dark:text-zinc-400 text-center mt-4">
              Pour une meilleure lecture sur mobile, ouvrez le PDF dans un
              nouvel onglet
            </p>
          </div>

          {/* Version desktop : iframe optimisée */}
          <div className="hidden md:block relative w-full h-[calc(100vh-200px)] min-h-[800px]">
            <iframe
              src="/BilanMandat.pdf#view=FitH&zoom=page-width"
              className="w-full h-full border-0"
              title="Bilan de mandat"
              style={{
                overflow: "hidden",
              }}
            />
          </div>
        </div>
      </section>
    </div>
  );
}
