// splash-hero.jsx — sticky nav + hero panel
// Both light and dark variants. Variant chosen by hero prop.

function Nav({ dark, onJoinClick }) {
  const navColor = dark ? baux.bone : baux.navy;
  const border = dark ? baux.white12 : baux.navy12;
  const [scrolled, setScrolled] = React.useState(false);
  const isMobile = useIsMobile();
  React.useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 12);
    onScroll();
    window.addEventListener('scroll', onScroll, { passive: true });
    return () => window.removeEventListener('scroll', onScroll);
  }, []);

  return (
    <nav style={{
      position: 'fixed', top: 0, left: 0, right: 0,
      zIndex: 100,
      height: isMobile ? 64 : 76,
      display: 'flex', alignItems: 'center', justifyContent: 'space-between',
      padding: isMobile ? '0 20px' : '0 32px',
      backgroundColor: scrolled
        ? (dark ? 'rgba(10,22,40,0.85)' : 'rgba(246,241,231,0.88)')
        : 'transparent',
      borderBottom: scrolled ? `1px solid ${border}` : '1px solid transparent',
      backdropFilter: scrolled ? 'blur(16px) saturate(150%)' : 'none',
      WebkitBackdropFilter: scrolled ? 'blur(16px) saturate(150%)' : 'none',
      transition: 'background 240ms ease, border-color 240ms ease',
      color: navColor,
    }}>
      <a href="#top" style={{ textDecoration: 'none', display: 'inline-flex', alignItems: 'baseline' }}>
        <Wordmark size={isMobile ? 18 : 22} color={navColor}/>
      </a>

      <div style={{
        display: 'flex', alignItems: 'center',
        gap: isMobile ? 14 : 28,
      }}>
        {!isMobile && [
          { label: 'Travelers', href: '#top' },
          { label: 'Partners', href: '#partners' },
        ].map((it) => (
          <a key={it.href} href={it.href} style={{
            color: dark ? baux.white72 : baux.navy85,
            textDecoration: 'none',
            fontFamily: baux.fontSans, fontSize: 14, fontWeight: 500,
            letterSpacing: 0,
            transition: 'color 200ms',
          }}
          onMouseEnter={(e) => (e.currentTarget.style.color = navColor)}
          onMouseLeave={(e) => (e.currentTarget.style.color = dark ? baux.white72 : baux.navy85)}
          >{it.label}</a>
        ))}
        <Button
          tone="accent"
          onClick={(e) => { e.preventDefault(); onJoinClick && onJoinClick(); }}
          style={{
            padding: isMobile ? '8px 14px' : '10px 18px',
            fontSize: isMobile ? 13 : 14,
          }}>
          Join the BETA
        </Button>
      </div>
    </nav>
  );
}

// ────────────────────────────────────────────────────────────────────────────
function Hero({ dark, onJoinClick, onSubmitEmail }) {
  const fg     = dark ? baux.bone : baux.navy;
  const fg2    = dark ? baux.white72 : baux.navy85;
  const fg3    = dark ? baux.white48 : baux.navy60;
  const accent = baux.gold;
  const bg     = dark ? baux.navy : baux.bone;
  const isMobile = useIsMobile();
  const isTablet = useIsTablet();
  // size the hero phone to fit on narrow viewports
  const primaryPhone = isMobile ? 240 : (isTablet ? 280 : 340);
  const ghostPhone   = isMobile ? 180 : (isTablet ? 220 : 260);

  return (
    <section id="top" style={{
      position: 'relative',
      background: bg,
      color: fg,
      paddingTop: isMobile ? 100 : 140,
      paddingBottom: isMobile ? 56 : 96,
      overflow: 'hidden',
    }}>
      {/* stylized abstract street map */}
      <HeroMap dark={dark}/>

      {/* soft gold halo on right side */}
      <div style={{
        position: 'absolute',
        top: '15%', right: '-12%',
        width: isMobile ? 480 : 720, height: isMobile ? 480 : 720,
        borderRadius: '50%',
        background: dark
          ? 'radial-gradient(circle, rgba(200,169,110,0.18) 0%, rgba(200,169,110,0) 60%)'
          : 'radial-gradient(circle, rgba(200,169,110,0.28) 0%, rgba(200,169,110,0) 60%)',
        pointerEvents: 'none',
        filter: 'blur(2px)',
      }}/>

      <div style={{
        maxWidth: 1200, margin: '0 auto',
        padding: isMobile ? '0 20px' : '0 32px',
        position: 'relative',
        display: 'grid',
        gridTemplateColumns: isTablet ? 'minmax(0, 1fr)' : 'minmax(0, 1.05fr) minmax(0, 0.95fr)',
        gap: isMobile ? 40 : 64,
        alignItems: 'center',
      }}>
        {/* LEFT */}
        <div style={{ order: isTablet ? 2 : 0 }}>
          <h1 style={{
            margin: 0,
            fontFamily: baux.fontSans,
            fontSize: isMobile ? 40 : (isTablet ? 56 : 72),
            fontWeight: 700,
            letterSpacing: '-0.025em',
            lineHeight: 1.02,
            color: fg,
            maxWidth: 620,
          }}>
            Travel with your own{' '}
            <span style={{
              fontFamily: baux.fontSerif,
              fontStyle: 'italic',
              fontWeight: 400,
              color: accent,
            }}>local</span>{' '}
            guide.
          </h1>

          <p style={{
            margin: isMobile ? '20px 0 24px' : '28px 0 32px',
            maxWidth: 520,
            fontFamily: baux.fontSans,
            fontSize: isMobile ? 16 : 19,
            fontWeight: 400,
            color: fg2,
            lineHeight: 1.55,
          }}>
            BAUX is the world's only Place Intelligence platform — a place where every destination has a voice.
          </p>

          <div style={{
            fontFamily: baux.fontSerif,
            fontStyle: 'italic',
            fontWeight: 400,
            fontSize: isMobile ? 16 : 18,
            color: accent,
            marginBottom: 12,
            letterSpacing: 0,
            lineHeight: 1.3,
          }}>
            Be the first to hear the world.
          </div>

          <div style={{ marginBottom: 0 }}>
            <InlineEmailForm dark={dark} onSubmit={onSubmitEmail} compact/>
            <div style={{
              marginTop: 14,
              fontFamily: baux.fontSans, fontSize: 13,
              color: fg3,
            }}>
              No spam. One email when BAUX goes live.
            </div>
          </div>
        </div>

        {/* RIGHT — phone mock */}
        <div style={{
          position: 'relative',
          display: 'flex', alignItems: 'center', justifyContent: 'center',
          minHeight: isMobile ? 420 : (isTablet ? 520 : 720),
          // on mobile/tablet the column moves below the text — push the visual
          // a touch right so the ghosted phone has room
          paddingLeft: isMobile ? 40 : 0,
          order: isTablet ? 1 : 0,
        }}>
          {/* second phone, ghosted behind — scaled down on mobile */}
          <div style={{
            position: 'absolute',
            transform: `translate(${isMobile ? '-72px' : (isTablet ? '-90px' : '-110px')}, ${isMobile ? '24px' : '30px'}) rotate(-9deg)`,
            opacity: 0.45,
            filter: 'blur(0.5px)',
          }}>
            <PhoneFrame src="assets/screens/ios-mills50.png" width={ghostPhone}/>
          </div>

          {/* primary phone */}
          <div style={{
            position: 'relative',
            transform: 'rotate(-2deg)',
            animation: 'floaty 8s ease-in-out infinite',
            zIndex: 2,
          }}>
            <PhoneFrame src="assets/screens/ios-orlando-welcome.png" width={primaryPhone}/>
          </div>
        </div>
      </div>
    </section>
  );
}

window.Nav = Nav;
window.Hero = Hero;
