---
// Footer.astro - V1.4-F : 1 ligne 3 zones (nav / subscribe / logos RS).
// Alignement vertical centre + padding-y reduit (py-2) pour profil plus fin.
// Subscribe input/button compact (py-1) cale sur baseline des autres elements.
---
<footer class="border-t border-neutral-200 px-6 py-2 bg-[#FAFAF7] text-[#0F172A]">
  <div class="flex flex-col md:flex-row md:items-center md:justify-between gap-2 md:gap-6">

    <!-- ZONE GAUCHE : liens nav -->
    <nav class="flex gap-4 text-xs items-center justify-center md:justify-start">
      <a href="/manifeste" data-manifeste-link class="opacity-60 hover:opacity-100 transition-opacity">Manifeste</a>
      <a href="/a-propos" class="opacity-60 hover:opacity-100 transition-opacity">A propos</a>
      <a href="/mentions-legales" class="opacity-60 hover:opacity-100 transition-opacity">Mentions legales</a>
    </nav>

    <!-- ZONE CENTRE : subscribe form compact (endpoint /api/subscribe V1.1-I).
         V1.4-F : padding-y reduit (py-1) pour caler input sur la baseline des liens + logos. -->
    <div class="flex flex-col items-center gap-0.5">
      <form id="subscribe-form" class="flex gap-2 items-center">
        <input
          type="email"
          name="email"
          required
          placeholder="ton@email.fr"
          class="px-3 py-1 border border-neutral-300 rounded text-xs focus:outline-none focus:border-[#0F172A] bg-white leading-tight"
        />
        <button
          type="submit"
          class="px-3 py-1 bg-[#0F172A] text-white rounded text-xs hover:bg-[#475569] transition-colors whitespace-nowrap leading-tight"
        >
          s'abonner
        </button>
      </form>
      <p id="subscribe-msg" class="text-[10px] text-neutral-500 min-h-[0.75rem]"></p>
    </div>

    <!-- ZONE DROITE : logos RS cliquables (SVG inline, fill #0F172A 60%) -->
    <!-- V1.3-F : gap-4 mobile / gap-6 desktop pour espacer les logos. V1.4-F : items-center force baseline. -->
    <div class="flex gap-4 md:gap-6 items-center justify-center md:justify-end text-[#0F172A]">
      <!-- V1.4-bis FIX 6 : Instagram x2 (AEP politique + Jules perso) avec aria-labels distincts.
           V1.4-bis FIX 7 : SVG simplifie (camera carree avec coins arrondis, lentille, point flash) — rendu propre net. -->
      <a
        href="https://www.instagram.com/aep.politique/"
        target="_blank"
        rel="noopener noreferrer"
        aria-label="Instagram @aep.politique"
        title="@aep.politique"
        class="opacity-60 hover:opacity-100 transition-opacity"
      >
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="w-[18px] h-[18px] md:w-5 md:h-5" fill="currentColor" aria-hidden="true">
          <path d="M7.75 2C4.574 2 2 4.574 2 7.75v8.5C2 19.426 4.574 22 7.75 22h8.5C19.426 22 22 19.426 22 16.25v-8.5C22 4.574 19.426 2 16.25 2h-8.5zM4 7.75A3.75 3.75 0 017.75 4h8.5A3.75 3.75 0 0120 7.75v8.5A3.75 3.75 0 0116.25 20h-8.5A3.75 3.75 0 014 16.25v-8.5zM12 7a5 5 0 100 10 5 5 0 000-10zm0 2a3 3 0 110 6 3 3 0 010-6zm5.5-3.5a1 1 0 100 2 1 1 0 000-2z"/>
        </svg>
      </a>

      <!-- Instagram @julesneny (compte perso/art) -->
      <a
        href="https://www.instagram.com/julesneny/"
        target="_blank"
        rel="noopener noreferrer"
        aria-label="Instagram @julesneny"
        title="@julesneny"
        class="opacity-60 hover:opacity-100 transition-opacity"
      >
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="w-[18px] h-[18px] md:w-5 md:h-5" fill="currentColor" aria-hidden="true">
          <path d="M7.75 2C4.574 2 2 4.574 2 7.75v8.5C2 19.426 4.574 22 7.75 22h8.5C19.426 22 22 19.426 22 16.25v-8.5C22 4.574 19.426 2 16.25 2h-8.5zM4 7.75A3.75 3.75 0 017.75 4h8.5A3.75 3.75 0 0120 7.75v8.5A3.75 3.75 0 0116.25 20h-8.5A3.75 3.75 0 014 16.25v-8.5zM12 7a5 5 0 100 10 5 5 0 000-10zm0 2a3 3 0 110 6 3 3 0 010-6zm5.5-3.5a1 1 0 100 2 1 1 0 000-2z"/>
        </svg>
      </a>

      <!-- GitHub (TODO: si 404 connu, fallback https://git.trans-former.fr/jules Gitea) -->
      <a
        href="https://github.com/julesneny"
        target="_blank"
        rel="noopener noreferrer"
        aria-label="GitHub"
        class="opacity-60 hover:opacity-100 transition-opacity"
      >
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="w-[18px] h-[18px] md:w-5 md:h-5" fill="currentColor" aria-hidden="true">
          <path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/>
        </svg>
      </a>

      <!-- LinkedIn TODO: confirmer URL LinkedIn Jules -->
      <a
        href="https://www.linkedin.com/in/jules-neny/"
        target="_blank"
        rel="noopener noreferrer"
        aria-label="LinkedIn"
        class="opacity-60 hover:opacity-100 transition-opacity"
      >
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="w-[18px] h-[18px] md:w-5 md:h-5" fill="currentColor" aria-hidden="true">
          <path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.062 2.062 0 01-2.063-2.065 2.063 2.063 0 112.063 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/>
        </svg>
      </a>

      <!-- Substack -->
      <a
        href="https://julesneny.substack.com"
        target="_blank"
        rel="noopener noreferrer"
        aria-label="Substack"
        class="opacity-60 hover:opacity-100 transition-opacity"
      >
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="w-[18px] h-[18px] md:w-5 md:h-5" fill="currentColor" aria-hidden="true">
          <path d="M22.539 8.242H1.46V5.406h21.08v2.836zM1.46 10.812V24L12 18.11 22.54 24V10.812H1.46zM22.54 0H1.46v2.836h21.08V0z"/>
        </svg>
      </a>

      <!-- TODO V1.3 : ajouter logo Pinterest quand compte créé -->
    </div>

  </div>
</footer>

<script>
  const form = document.getElementById('subscribe-form') as HTMLFormElement | null;
  const msg = document.getElementById('subscribe-msg') as HTMLParagraphElement | null;

  form?.addEventListener('submit', async (e) => {
    e.preventDefault();
    if (!msg || !form) return;

    const emailInput = form.elements.namedItem('email') as HTMLInputElement;
    const email = emailInput?.value?.trim() ?? '';
    if (!email) return;

    msg.textContent = 'envoi...';

    try {
      const r = await fetch('/api/subscribe', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ email }),
      });
      const data = await r.json();
      if (data.ok) {
        msg.textContent = data.already
          ? 'tu es deja abonne - a tres vite.'
          : 'merci ! check ta boite mail (parfois spam).';
        form.reset();
      } else {
        msg.textContent = `souci : ${data.error || 'reessaie plus tard'}`;
      }
    } catch {
      msg.textContent = 'erreur reseau - reessaie plus tard';
    }
  });

  // V1.3-E : intercept clics liens Manifeste depuis le footer -> preview centrale sur racine.
  // Sur /a-propos, /mentions-legales, /manifeste lui-meme : navigation normale.
  document.querySelectorAll<HTMLAnchorElement>('a[data-manifeste-link]').forEach((el) => {
    el.addEventListener('click', (e) => {
      if (window.location.pathname === '/') {
        e.preventDefault();
        window.dispatchEvent(new CustomEvent('preview-open', { detail: { type: 'manifeste' } }));
      }
      // sinon : navigation normale vers /manifeste
    });
  });
</script>
