// EaglEye shared components — nav, footer, store badges, real app screenshots

// ── Icon atoms ──────────────────────────────────────────────
const EEIcon = ({ size = 28 }) => (
  <img
    src="/assets/app-icon.png"
    alt="EaglEye"
    width={size}
    height={size}
    style={{ borderRadius: size * 0.22, display: 'block', boxShadow: '0 0 0 1px rgba(255,255,255,0.08)' }}
  />
);

const Reticle = ({ size = 120, color = 'var(--reticle)', stroke = 1 }) => (
  <svg width={size} height={size} viewBox="0 0 120 120" style={{ display: 'block' }}>
    <circle cx="60" cy="60" r="58" fill="none" stroke={color} strokeWidth={stroke} opacity="0.4" />
    <circle cx="60" cy="60" r="38" fill="none" stroke={color} strokeWidth={stroke} opacity="0.6" />
    <circle cx="60" cy="60" r="2" fill={color} />
    <line x1="60" y1="2" x2="60" y2="44" stroke={color} strokeWidth={stroke} />
    <line x1="60" y1="76" x2="60" y2="118" stroke={color} strokeWidth={stroke} />
    <line x1="2" y1="60" x2="44" y2="60" stroke={color} strokeWidth={stroke} />
    <line x1="76" y1="60" x2="118" y2="60" stroke={color} strokeWidth={stroke} />
    {[20, 30, 40, 50, 70, 80, 90, 100].map(p => (
      <g key={p}>
        <line x1="60" y1={p} x2="63" y2={p} stroke={color} strokeWidth={stroke} opacity="0.7" />
        <line x1={p} y1="60" x2={p} y2="63" stroke={color} strokeWidth={stroke} opacity="0.7" />
      </g>
    ))}
  </svg>
);

// ── Store badges (original, not copies of Apple/Google marks) ──
const AppStoreBadge = ({ comingSoon = false, compact = false }) => (
  <a className={'ee-store' + (compact ? ' ee-store--compact' : '')} href="#" onClick={e => e.preventDefault()} style={{ position: 'relative', opacity: comingSoon ? 0.85 : 1 }}>
    <svg width="22" height="26" viewBox="0 0 22 26" fill="none">
      <path d="M15.3 6.2c.9-1.1 1.5-2.6 1.3-4.2-1.3.1-2.9.9-3.8 2-.8.9-1.5 2.5-1.3 4 1.5.1 3-.7 3.8-1.8zm2.8 8.4c0-3 2.4-4.4 2.5-4.5-1.4-2-3.5-2.3-4.3-2.3-1.8-.2-3.5 1.1-4.5 1.1-.9 0-2.4-1.1-3.9-1-2 0-3.9 1.2-4.9 3-2.1 3.6-.5 9 1.5 11.9 1 1.4 2.2 3 3.7 2.9 1.5-.1 2-1 3.8-1s2.3 1 3.9 1c1.6 0 2.6-1.4 3.6-2.8 1.1-1.6 1.6-3.2 1.6-3.3-.1 0-3-1.2-3-4z" fill="#fff"/>
    </svg>
    <div className="ee-store-label">
      <span className="ee-store-small">Download on the</span>
      <span className="ee-store-big">App Store</span>
    </div>
    {comingSoon && (
      <span style={{
        position: 'absolute', top: -10, right: compact ? -6 : -12, transform: 'rotate(6deg)',
        background: 'var(--gold)', color: '#0a0a08',
        fontFamily: 'var(--f-mono)', fontSize: compact ? 8 : 9.5, fontWeight: 700,
        letterSpacing: '0.16em', padding: compact ? '3px 6px' : '4px 8px',
        border: '1.5px solid #0a0a08', borderRadius: 2,
        boxShadow: '0 2px 8px rgba(0,0,0,0.4)', whiteSpace: 'nowrap',
      }}>COMING SOON</span>
    )}
  </a>
);

const GooglePlayBadge = ({ comingSoon = false, compact = false }) => (
  <a className={'ee-store' + (compact ? ' ee-store--compact' : '')} href="#" onClick={e => e.preventDefault()} style={{ position: 'relative', opacity: comingSoon ? 0.85 : 1 }}>
    <svg width="22" height="26" viewBox="0 0 22 26" fill="none">
      <path d="M1.5 1.4c-.3.3-.5.8-.5 1.4v20.4c0 .6.2 1.1.5 1.4l.1.1L13 13.1v-.2L1.6 1.4h-.1z" fill="#4a7a9e"/>
      <path d="M16.8 16.9l-3.8-3.8v-.2l3.8-3.8.1.1 4.5 2.6c1.3.7 1.3 1.9 0 2.6l-4.6 2.5z" fill="#d4a24c"/>
      <path d="M16.9 16.8L13 13 1.5 24.6c.4.5 1.2.5 2 .1l13.4-7.9" fill="#c3342b"/>
      <path d="M16.9 9.2L3.5 1.3c-.8-.4-1.6-.4-2 .1L13 13l3.9-3.8z" fill="#6b7a4f"/>
    </svg>
    <div className="ee-store-label">
      <span className="ee-store-small">Get it on</span>
      <span className="ee-store-big">Google Play</span>
    </div>
    {comingSoon && (
      <span style={{
        position: 'absolute', top: -10, right: compact ? -6 : -12, transform: 'rotate(6deg)',
        background: 'var(--gold)', color: '#0a0a08',
        fontFamily: 'var(--f-mono)', fontSize: compact ? 8 : 9.5, fontWeight: 700,
        letterSpacing: '0.16em', padding: compact ? '3px 6px' : '4px 8px',
        border: '1.5px solid #0a0a08', borderRadius: 2,
        boxShadow: '0 2px 8px rgba(0,0,0,0.4)', whiteSpace: 'nowrap',
      }}>COMING SOON</span>
    )}
  </a>
);

// ── Nav ─────────────────────────────────────────────────────
const EENav = ({ variant = 'dark', active }) => (
  <nav style={{
    display: 'flex', alignItems: 'center', justifyContent: 'space-between',
    padding: '18px 48px', borderBottom: '1px solid var(--hair)',
    background: variant === 'dark' ? 'rgba(7,9,12,0.85)' : 'transparent',
    backdropFilter: 'blur(10px)', position: 'relative', zIndex: 10,
  }}>
    <a href="/" style={{ display: 'flex', alignItems: 'center', gap: 14, textDecoration: 'none', color: 'var(--bone)' }}>
      <EEIcon size={44} />
      <div style={{ display: 'flex', flexDirection: 'column', lineHeight: 1 }}>
        <span style={{ fontFamily: 'var(--f-display)', fontWeight: 800, letterSpacing: '-0.01em', fontSize: 28 }}>
          EaglEye<span style={{ color: 'var(--gold)' }}>.</span>
        </span>
        <span className="mono" style={{ fontSize: 11, letterSpacing: '0.35em', color: 'var(--tan)', marginTop: 5 }}>B A L L I S T I C S</span>
      </div>
    </a>
    <div style={{ display: 'flex', gap: 32, fontSize: 15, color: 'var(--bone-2)' }}>
      {[
        { label: 'Features', href: '#features' },
        { label: 'Precision', href: '#precision' },
        { label: 'Themes', href: '#themes' },
        { label: 'Pricing', href: '#pricing' },
        { label: 'Support', href: 'mailto:hello@gadsden.io' },
      ].map(i => (
        <a key={i.label} href={i.href} style={{
          color: active === i.label ? 'var(--bone)' : 'var(--bone-2)',
          textDecoration: 'none', fontWeight: 500,
        }}>{i.label}</a>
      ))}
    </div>
    <div style={{ display: 'flex', alignItems: 'center', gap: 14 }}>
      <a href="https://x.com/EaglEyeDope" target="_blank" rel="noopener" aria-label="Follow EaglEye on X" style={{
        display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
        width: 30, height: 30, color: 'var(--bone-2)', textDecoration: 'none',
        border: '1px solid var(--hair-2)', borderRadius: 3, transition: 'color 0.15s, border-color 0.15s',
      }}
      onMouseEnter={e => { e.currentTarget.style.color = 'var(--gold)'; e.currentTarget.style.borderColor = 'var(--gold)'; }}
      onMouseLeave={e => { e.currentTarget.style.color = 'var(--bone-2)'; e.currentTarget.style.borderColor = 'var(--hair-2)'; }}
      >
        <svg width="13" height="13" viewBox="0 0 24 24" fill="currentColor"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg>
      </a>
      <span className="mono" style={{ fontSize: 12, color: 'var(--bone-4)' }}>v1.0</span>
      <a href="#pricing" className="ee-btn" style={{ padding: '10px 16px', fontSize: 14 }}>Download</a>
    </div>
  </nav>
);

// ── Footer (email only — no address) ────────────────────────
const EEFooter = () => (
  <footer style={{
    background: 'var(--ink-0)', padding: '56px 48px 32px', borderTop: '1px solid var(--hair)',
  }}>
    <div style={{ display: 'grid', gridTemplateColumns: '1.4fr 1fr 1fr 1fr 1fr', gap: 48, marginBottom: 48 }}>
      <div>
        <div style={{ display: 'flex', alignItems: 'center', gap: 14, marginBottom: 14 }}>
          <EEIcon size={46} />
          <div style={{ display: 'flex', flexDirection: 'column', lineHeight: 1 }}>
            <span style={{ fontFamily: 'var(--f-display)', fontWeight: 800, fontSize: 30, letterSpacing: '-0.01em' }}>
              EaglEye<span style={{ color: 'var(--gold)' }}>.</span>
            </span>
            <span className="mono" style={{ fontSize: 12, letterSpacing: '0.35em', color: 'var(--tan)', marginTop: 5 }}>B A L L I S T I C S</span>
          </div>
        </div>
        <p style={{ color: 'var(--bone-3)', fontSize: 15, lineHeight: 1.6, maxWidth: 360, margin: 0 }}>
          Precision long-range ballistic calculator. Built for shooters who measure in MILs, not
          marketing claims.
        </p>
      </div>
      {[
        { h: 'Product', l: [
          { label: 'Features', href: '/#features' },
          { label: 'Precision', href: '/#precision' },
          { label: 'Themes', href: '/#themes' },
          { label: 'Pricing', href: '/#pricing' },
        ] },
        { h: 'Legal', l: [
          { label: 'Privacy Policy', href: '/privacy' },
          { label: 'EULA', href: '/eula' },
        ] },
        { h: 'Follow', l: [
          { label: '@EaglEyeDope', href: 'https://x.com/EaglEyeDope', external: true },
        ] },
        { h: 'Contact', l: [
          { label: 'hello@gadsden.io', href: 'mailto:hello@gadsden.io' },
        ] },
      ].map(col => (
        <div key={col.h}>
          <div className="eyebrow" style={{ marginBottom: 14 }}>{col.h}</div>
          {col.l.map(i => (
            <a key={i.label} href={i.href}
              target={i.external ? '_blank' : undefined}
              rel={i.external ? 'noopener' : undefined}
              style={{
                display: 'block', fontSize: 15,
                color: (col.h === 'Contact' || col.h === 'Follow') ? 'var(--gold)' : 'var(--bone-2)',
                marginBottom: 10,
                fontFamily: (col.h === 'Contact' || col.h === 'Follow') ? 'var(--f-mono)' : 'inherit',
                textDecoration: 'none',
              }}>{i.label}</a>
          ))}
        </div>
      ))}
    </div>
    <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', paddingTop: 24, borderTop: '1px solid var(--hair)' }}>
      <span className="mono" style={{ fontSize: 12, color: 'var(--bone-4)', letterSpacing: '0.06em' }}>
        © 2026 GADSDEN LLC · EAGLEYE BALLISTICS
      </span>
      <span className="mono" style={{ fontSize: 12, color: 'var(--bone-4)', letterSpacing: '0.06em' }}>
        NO ANALYTICS · NO TRACKING · NO ACCOUNTS
      </span>
    </div>
  </footer>
);

// ── Real phone mockup: uses a .png screenshot, wraps in bezel ──
// Screenshots are 1320x2868 (iPhone 15 Pro Max) — ratio 0.460
const BUST = '?v=209'; // bump to force reload when screenshots change
const PhoneShot = ({ src, width = 260, style, bare = false }) => {
  const height = Math.round(width / 0.460);
  const bustedSrc = src + BUST;
  if (bare) {
    // Just the raw screen (for embedding in laid-out grids w/o bezels)
    return (
      <img src={bustedSrc} alt="" style={{
        width, height, display: 'block', borderRadius: width * 0.09,
        objectFit: 'cover',
        boxShadow: '0 30px 60px -20px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.06)',
        ...style,
      }}/>
    );
  }
  return (
    <div style={{
      width: width + 16, padding: 8,
      background: '#000', borderRadius: width * 0.14,
      boxShadow: `
        0 0 0 1.5px #2a3240,
        0 0 0 4px #0a0e13,
        0 40px 80px -20px rgba(0,0,0,0.8),
        0 20px 40px -10px rgba(0,0,0,0.6)`,
      ...style,
    }}>
      <img src={bustedSrc} alt="" style={{
        width, height, display: 'block',
        borderRadius: width * 0.1,
        objectFit: 'cover',
      }}/>
    </div>
  );
};

// Legacy names kept — both DopeCardScreen and SolveScreen map onto screenshots now.
// Callers pass `theme` — we pick the corresponding screenshot.
const DopeCardScreen = ({ theme = 'dark' }) => {
  const map = {
    dark: 'assets/screens/dopecard-dark.png',
    oled: 'assets/screens/dopecard-oled.png',
    daylight: 'assets/screens/dopecard-daylight.png',
    patriot: 'assets/screens/dopecard-patriotic-dark.png',
    'patriot-dark': 'assets/screens/dopecard-patriotic-dark.png',
    'patriot-light': 'assets/screens/dopecard-patriotic-light.png',
  };
  return <img src={(map[theme] || map.dark) + BUST} alt="Dope card" style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }} />;
};

const SolveScreen = ({ theme = 'dark' }) => (
  <img src={'assets/screens/solver-weather.png' + BUST} alt="Solver" style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }} />
);

Object.assign(window, {
  EEIcon, Reticle, AppStoreBadge, GooglePlayBadge,
  EENav, EEFooter, DopeCardScreen, SolveScreen, PhoneShot,
});
