// LinkedClean — Landing page sections
// Reaproveita lc-brand-v2.jsx (LCB tokens, LCBHero, LCBLockup, LCBIcon, LCBButton, LCBPillNav, LCBHeadline)

const { useState, useRef, useEffect, useCallback } = React;

// =============================================================================
// SHARED SHELL — Nav + Footer
// =============================================================================
function LCNav({ active }) {
  const { LCB, LCBLockup } = window;
  const items = [
    { label: 'Como funciona', href: '/#como-funciona' },
    { label: 'Manifesto',     href: '/manifesto' },
    { label: 'Privacidade',   href: '/privacidade' },
  ];
  return (
    <div style={{
      position: 'sticky', top: 0, zIndex: 50,
      paddingTop: 20, paddingBottom: 20,
      display: 'flex', justifyContent: 'center',
      background: 'linear-gradient(180deg, rgba(250,250,249,0.96) 0%, rgba(250,250,249,0.85) 70%, rgba(250,250,249,0) 100%)',
      backdropFilter: 'blur(8px)',
    }}>
      <nav style={{
        background: '#FFFFFF',
        borderRadius: LCB.rPill,
        padding: '6px 6px 6px 18px',
        display: 'inline-flex', alignItems: 'center', gap: 4,
        fontFamily: LCB.fontSans, fontSize: 14, fontWeight: 500,
        border: `1px solid ${LCB.ink10}`,
        boxShadow: '0 1px 2px rgba(10,10,10,0.04), 0 4px 12px -4px rgba(10,10,10,0.04)',
      }}>
        <a href="/" style={{
          display: 'inline-flex', alignItems: 'center', gap: 8,
          paddingRight: 14, marginRight: 4,
          color: LCB.ink, fontWeight: 600, letterSpacing: '-0.01em',
          borderRight: `1px solid ${LCB.ink10}`,
          textDecoration: 'none',
        }}>
          <LCBLockup iconSize={20} textSize={14} gap={7} />
        </a>
        {items.map((it, i) => (
          <a key={i} href={it.href} className="lc-nav-link" style={{
            padding: '8px 14px',
            color: active === it.label ? LCB.ink : LCB.ink60,
            background: active === it.label ? LCB.ink05 : 'transparent',
            cursor: 'pointer', textDecoration: 'none',
            borderRadius: LCB.rPill, letterSpacing: '-0.005em',
            fontWeight: active === it.label ? 600 : 500,
          }}>{it.label}</a>
        ))}
        <a
          href="https://chromewebstore.google.com/detail/linkedclean/pmbdfbcmlbekpehpafloidglmkgejmon"
          target="_blank"
          rel="noopener noreferrer"
          style={{
          background: LCB.ink, color: '#FFFFFF',
          border: 'none', borderRadius: LCB.rPill,
          padding: '8px 16px',
          fontFamily: LCB.fontSans, fontSize: 13, fontWeight: 600,
          letterSpacing: '-0.005em', cursor: 'pointer',
          textDecoration: 'none',
          display: 'inline-flex', alignItems: 'center', gap: 6,
        }}>
          <svg width="12" height="12" viewBox="0 0 12 12" fill="none">
            <path d="M6 1.5v6m0 0L3.5 5M6 7.5L8.5 5M2 9.5h8" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
          </svg>
          Adicionar ao Chrome
        </a>
      </nav>
    </div>
  );
}
window.LCNav = LCNav;

function LCFooter() {
  const { LCB, LCBLockup } = window;
  return (
    <footer style={{
      borderTop: `1px solid ${LCB.ink10}`,
      padding: '56px 56px 40px',
      background: LCB.paper,
      fontFamily: LCB.fontSans,
    }}>
      <div style={{
        maxWidth: 1168, margin: '0 auto',
        display: 'grid', gridTemplateColumns: '1.4fr 1fr 1fr 1fr',
        gap: 48, alignItems: 'flex-start',
      }}>
        <div>
          <LCBLockup iconSize={28} textSize={17} gap={9} />
          <p style={{
            fontSize: 14, color: LCB.ink60, lineHeight: 1.55,
            marginTop: 16, maxWidth: 280, letterSpacing: '-0.005em',
          }}>
            Limpe seu feed do LinkedIn
          </p>
        </div>
        {[
          { title: 'Produto', items: [['Como funciona', '/#como-funciona'], ['Categorias', '/#categorias'], ['Adicionar ao Chrome', 'https://chromewebstore.google.com/detail/linkedclean/pmbdfbcmlbekpehpafloidglmkgejmon']] },
          { title: 'Sobre',   items: [['Manifesto', '/manifesto'], ['Privacidade', '/privacidade'], ['FAQ', '/#faq']] },
          { title: 'Contato', items: [['hello@linkedclean.app', 'mailto:hello@linkedclean.app'], ['Reportar bug', 'mailto:hello@linkedclean.app']] },
        ].map((col, i) => (
          <div key={i}>
            <div style={{
              fontSize: 11, fontWeight: 600, color: LCB.ink60,
              textTransform: 'uppercase', letterSpacing: '0.14em', marginBottom: 14,
            }}>{col.title}</div>
            <ul style={{ margin: 0, padding: 0, listStyle: 'none', display: 'flex', flexDirection: 'column', gap: 9 }}>
              {col.items.map(([label, href], j) => {
                const external = href.startsWith('http');
                return (
                  <li key={j}>
                    <a
                      href={href}
                      target={external ? '_blank' : undefined}
                      rel={external ? 'noopener noreferrer' : undefined}
                      style={{
                        fontSize: 14, color: LCB.ink, textDecoration: 'none',
                        letterSpacing: '-0.005em',
                      }}
                    >{label}</a>
                  </li>
                );
              })}
            </ul>
          </div>
        ))}
      </div>
      <div style={{
        maxWidth: 1168, margin: '40px auto 0', paddingTop: 24,
        borderTop: `1px solid ${LCB.ink10}`,
        display: 'flex', justifyContent: 'space-between', alignItems: 'center',
        flexWrap: 'wrap', gap: 12,
      }}>
        <div style={{ fontFamily: LCB.fontMono, fontSize: 11, color: LCB.ink40 }}>
          linkedclean.app · v{window.LC_VERSION} · feito a base de café pelo{' '}
          <a
            href="https://www.linkedin.com/in/hugo-s-vasconcelos/"
            target="_blank"
            rel="noopener noreferrer"
            style={{ color: LCB.ink60, textDecoration: 'underline' }}
          >
            Hugo Vasconcelos
          </a>
        </div>
      </div>
    </footer>
  );
}
window.LCFooter = LCFooter;

// =============================================================================
// SECTION HEADER — eyebrow + título grande
// =============================================================================
function LCSectionHeader({ eyebrow, title, sub, align = 'center', maxWidth = 760 }) {
  const { LCB } = window;
  return (
    <div style={{ textAlign: align, maxWidth, margin: align === 'center' ? '0 auto' : 0 }}>
      <div style={{
        fontSize: 11, fontWeight: 600, color: LCB.ink60,
        textTransform: 'uppercase', letterSpacing: '0.14em', marginBottom: 16,
      }}>{eyebrow}</div>
      <h2 style={{
        fontSize: 56, fontWeight: 700, letterSpacing: '-0.035em',
        margin: 0, color: LCB.ink, lineHeight: 1.02,
      }}>{title}</h2>
      {sub && (
        <p style={{
          fontSize: 18, lineHeight: 1.5, color: LCB.ink60,
          margin: '20px auto 0', maxWidth: 580,
          letterSpacing: '-0.005em',
        }}>{sub}</p>
      )}
    </div>
  );
}
window.LCSectionHeader = LCSectionHeader;

// =============================================================================
// HERO (reaproveitado e refinado — sem número inventado no trust strip)
// =============================================================================
function LCLandingHero() {
  const { LCB, LCBIcon, LCBHeadline } = window;
  return (
    <section style={{
      position: 'relative',
      paddingTop: 64, paddingBottom: 96,
      paddingLeft: 56, paddingRight: 56,
      textAlign: 'center',
      overflow: 'hidden',
    }}>
      {/* big icon */}
      <div style={{ display: 'flex', justifyContent: 'center', marginBottom: 40 }}>
        <LCBIcon size={104} />
      </div>

      <LCBHeadline size={92} align="center" maxWidth={1000}>
        Limpe seu feed do LinkedIn
      </LCBHeadline>

      <p style={{
        fontSize: 19, lineHeight: 1.5, color: LCB.ink60,
        margin: '24px auto 40px',
        maxWidth: 620, fontWeight: 400, letterSpacing: '-0.005em',
      }}>
        Oculte patrocinados, política e vídeos. Fuja de iscas de engajamento. Você no controle do algoritmo.
      </p>

      <div style={{
        display: 'flex', justifyContent: 'center', gap: 12,
        marginBottom: 56, flexWrap: 'wrap',
      }}>
        <a
          href="https://chromewebstore.google.com/detail/linkedclean/pmbdfbcmlbekpehpafloidglmkgejmon"
          target="_blank"
          rel="noopener noreferrer"
          style={{
          background: LCB.ink, color: '#FFFFFF',
          border: `1px solid ${LCB.ink}`, borderRadius: LCB.rPill,
          padding: '14px 24px',
          fontFamily: LCB.fontSans, fontSize: 15, fontWeight: 600,
          letterSpacing: '-0.005em', textDecoration: 'none',
          display: 'inline-flex', alignItems: 'center', gap: 8,
        }}>
          <svg width="14" height="14" viewBox="0 0 12 12" fill="none">
            <path d="M6 1.5v6m0 0L3.5 5M6 7.5L8.5 5M2 9.5h8" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
          </svg>
          Adicionar ao Chrome
        </a>
        <a href="#como-funciona" style={{
          background: '#FFFFFF', color: LCB.ink,
          border: `1px solid ${LCB.ink20}`, borderRadius: LCB.rPill,
          padding: '14px 24px',
          fontFamily: LCB.fontSans, fontSize: 15, fontWeight: 600,
          letterSpacing: '-0.005em', textDecoration: 'none',
          display: 'inline-flex', alignItems: 'center', gap: 8,
        }}>
          Ver como funciona
          <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
            <path d="M3 7h8m0 0L7.5 3.5M11 7l-3.5 3.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
          </svg>
        </a>
      </div>

      {/* trust strip — sem número inventado */}
      <div style={{
        display: 'inline-flex', alignItems: 'center', gap: 12,
        padding: '10px 18px',
        background: '#FFFFFF',
        border: `1px solid ${LCB.ink10}`,
        borderRadius: LCB.rPill,
        fontSize: 13, color: LCB.ink60,
        letterSpacing: '-0.005em',
      }}>
        <span style={{
          display: 'inline-flex', width: 8, height: 8, borderRadius: '50%',
          background: LCB.success,
        }} />
        Sem login · Sem dados coletados · Sem deixar lento
      </div>
    </section>
  );
}
window.LCLandingHero = LCLandingHero;

// =============================================================================
// BEFORE / AFTER — slider arrastável
// =============================================================================
function LCBeforeAfter() {
  const { LCB, LCSectionHeader } = window;

  // 4 categorias canônicas, cada uma com cor de avatar distinta.
  // O ciclo total da animação é 8s; cada card fica 50% normal + 50% oculto,
  // staggered 2s entre eles → "varredura" sequencial passa pelos 4 cards.
  const posts = [
    { color: '#FB923C', tag: 'Patrocinado' },
    { color: '#A855F7', tag: 'Iscas de engajamento' },
    { color: '#10B981', tag: 'Vídeo' },
    { color: '#3B82F6', tag: 'Conteúdo político' },
  ];

  return (
    <section id="antes-depois" style={{
      padding: '96px 56px',
      background: LCB.paper,
    }}>
      <style>{`
        .lc-feed-anim {
          display: flex; flex-direction: column; gap: 12px;
          width: 100%; max-width: 720px;
          margin: 56px auto 0;
        }
        .lc-feed-card {
          position: relative;
          height: 88px;
          border-radius: 14px;
        }
        .lc-feed-card-normal,
        .lc-feed-card-hidden {
          position: absolute; inset: 0;
          padding: 16px 20px;
          display: flex; align-items: center;
          will-change: opacity, transform;
          animation-duration: 6s;
          animation-iteration-count: infinite;
          animation-timing-function: ease-in-out;
        }
        .lc-feed-card-normal {
          gap: 16px;
          background: #FFFFFF;
          border: 1px solid ${LCB.ink10};
          border-radius: 14px;
          animation-name: lc-feed-sweep-out;
        }
        .lc-feed-card-hidden {
          justify-content: center;
          background: ${LCB.paper};
          border: 1px dashed ${LCB.ink20};
          border-radius: 14px;
          font-family: ${LCB.fontMono};
          font-size: 13px;
          font-weight: 500;
          color: ${LCB.ink40};
          letter-spacing: 0.02em;
          animation-name: lc-feed-snap-in;
          opacity: 0;
        }
        .lc-feed-avatar {
          width: 40px; height: 40px;
          border-radius: 50%;
          flex-shrink: 0;
        }
        .lc-feed-lines {
          flex: 1; min-width: 0;
          display: flex; flex-direction: column; gap: 8px;
        }
        .lc-feed-line {
          height: 9px;
          background: ${LCB.ink10};
          border-radius: 4px;
        }
        .lc-feed-line-1 { width: 50%; }
        .lc-feed-line-2 { width: 90%; }

        /* Post normal: visível, depois desliza 12px pra esquerda fazendo
           fade-out. Volta de longe-direita ao final do ciclo. */
        @keyframes lc-feed-sweep-out {
          0%, 30%   { opacity: 1; transform: translateX(0); }
          45%, 80%  { opacity: 0; transform: translateX(-12px); }
          88%      { opacity: 0; transform: translateX(8px); }
          100%      { opacity: 1; transform: translateX(0); }
        }
        /* Card oculto: encaixa no lugar com micro scale-up, fica visível
           a maior parte do tempo, depois fade-out limpo. */
        @keyframes lc-feed-snap-in {
          0%, 30%   { opacity: 0; transform: scale(0.96); }
          45%, 80%  { opacity: 1; transform: scale(1); }
          88%, 100% { opacity: 0; transform: scale(0.96); }
        }

        @media (prefers-reduced-motion: reduce) {
          .lc-feed-card-normal,
          .lc-feed-card-hidden { animation: none; transform: none; }
          .lc-feed-card-hidden { opacity: 0; }
        }
      `}</style>

      <div style={{ maxWidth: 1168, margin: '0 auto' }}>
        <LCSectionHeader
          eyebrow="Antes · depois"
          title="Mesmo feed, sem ruído"
          sub="A diferença é o que você não vê."
        />

        <div className="lc-feed-anim" aria-hidden="true">
          {posts.map((p, i) => (
            <div key={i} className="lc-feed-card">
              <div
                className="lc-feed-card-normal"
                style={{ animationDelay: `${i * 1.5}s` }}
              >
                <div className="lc-feed-avatar" style={{ background: p.color }} />
                <div className="lc-feed-lines">
                  <span className="lc-feed-line lc-feed-line-1" />
                  <span className="lc-feed-line lc-feed-line-2" />
                </div>
              </div>
              <div
                className="lc-feed-card-hidden"
                style={{ animationDelay: `${i * 1.5}s` }}
              >
                {p.tag} · oculto
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}
window.LCBeforeAfter = LCBeforeAfter;
