// Hero — typographic primary; variants: type, accent, image
const HeroCountdown = ({ targetISO }) => {
  const [now, setNow] = React.useState(() => new Date());
  React.useEffect(() => {
    const id = setInterval(() => setNow(new Date()), 1000);
    return () => clearInterval(id);
  }, []);
  const target = new Date(targetISO);
  const diff = Math.max(0, target - now);
  const days = Math.floor(diff / 86400000);
  const hrs = Math.floor(diff / 3600000) % 24;
  const mins = Math.floor(diff / 60000) % 60;
  const secs = Math.floor(diff / 1000) % 60;
  const cell = (n, l) =>
  <div className="hc-cell" style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', minWidth: 56 }}>
      <div style={{ fontFamily: '"Space Grotesk"', fontSize: 28, fontWeight: 600, color: '#0E1B2E',
      lineHeight: 1, fontVariantNumeric: 'tabular-nums' }}>
        {String(n).padStart(2, '0')}
      </div>
      <div style={{ fontSize: 10, fontWeight: 700, color: '#6B7E92', textTransform: 'uppercase',
      letterSpacing: 1, marginTop: 6 }}>{l}</div>
    </div>;

  return (
    <div className="hc-wrap" style={{ display: 'inline-flex', gap: 0, alignItems: 'center',
      background: '#FFFFFF', border: '1px solid #DCE4EC',
      borderRadius: 14, padding: '14px 22px',
      boxShadow: 'rgba(46,92,138,0.08) 0px 4px 12px' }}>
      {cell(days, 'Days')}
      <div className="hc-divider" style={{ width: 1, height: 32, background: '#E1ECF7', margin: '0 18px' }} />
      {cell(hrs, 'Hrs')}
      <div className="hc-divider" style={{ width: 1, height: 32, background: '#E1ECF7', margin: '0 18px' }} />
      {cell(mins, 'Mins')}
      <div className="hc-divider" style={{ width: 1, height: 32, background: '#E1ECF7', margin: '0 18px' }} />
      {cell(secs, 'Secs')}
      <style>{`
        @media (max-width: 480px) {
          .hc-wrap { padding: 12px 14px !important; }
          .hc-cell { min-width: 44px !important; }
          .hc-divider { margin: 0 10px !important; }
        }
      `}</style>
    </div>);

};

const Hero = ({ variant = 'type' }) => {
  // Apply by 20 May 2026 — for cohort starting week of 24 May 2026
  const APPLY_BY = '2026-05-20T23:59:00+01:00';
  const START_LABEL = 'Week of 24 May 2026';
  const APPLY_LABEL = 'Apply by 20 May';

  const Headline = () =>
  <h1 className="hero-headline" style={{
    fontFamily: '"Space Grotesk"',
    fontSize: 'clamp(38px, 7.4vw, 96px)',
    fontWeight: 700,
    lineHeight: 1.0,
    letterSpacing: '-2.5px',
    color: '#0E1B2E',
    margin: 0,
    overflowWrap: 'break-word',
    hyphens: 'auto'
  }}>
      Apply AI in your practice.<br />
      Not just learn about it.<br />
      <span style={{
      color: variant === 'accent' ? '#E8B225' : '#0E1B2E',
      fontStyle: 'italic', fontWeight: 500
    }}></span>
    </h1>;


  const Sub = () =>
  <p style={{
    fontFamily: 'Rubik', fontSize: 'clamp(17px, 1.4vw, 20px)',
    lineHeight: 1.55, color: '#3F5670',
    marginTop: 28, maxWidth: 620
  }}>
      A 12-week cohort programme for educators who already know AI matters and are
      ready to make it part of how they actually teach. Small group. Live weekly
      sessions. Applied work in your real classroom every week.
    </p>;


  const CTAs = () =>
  <div style={{ display: 'flex', gap: 12, marginTop: 36, flexWrap: 'wrap' }}>
      <a href="https://form.jotform.com/261244735080049" target="_blank" rel="noopener noreferrer" style={{
      background: '#2E5C8A', color: '#FFFFFF',
      fontSize: 14, fontWeight: 700, textTransform: 'uppercase', letterSpacing: 0.6,
      padding: '16px 24px', borderRadius: 13,
      display: 'inline-flex', alignItems: 'center', gap: 10,
      transition: 'background 160ms, transform 160ms'
    }}
    onMouseEnter={(e) => {e.currentTarget.style.background = '#234A70';}}
    onMouseLeave={(e) => {e.currentTarget.style.background = '#2E5C8A';}}>
        Apply for the spring cohort
        <i data-lucide="arrow-right" style={{ width: 16, height: 16 }}></i>
      </a>
      <a href="#curriculum" style={{
      background: '#FFFFFF', color: '#2E5C8A',
      fontSize: 14, fontWeight: 700, textTransform: 'uppercase', letterSpacing: 0.6,
      padding: '16px 24px', borderRadius: 13,
      border: '1.5px solid #2E5C8A',
      display: 'inline-flex', alignItems: 'center', gap: 10
    }}>
        See the curriculum
      </a>
    </div>;


  const Meta = () =>
  <div style={{
    display: 'flex', gap: 24, marginTop: 24, flexWrap: 'wrap',
    fontSize: 13, color: '#6B7E92', fontWeight: 500
  }}>
      <span style={{ display: 'inline-flex', alignItems: 'center', gap: 8 }}>
        <span style={{ display: 'inline-block', width: 6, height: 6, borderRadius: '50%',
        background: '#E8B225' }} />
        15 places only
      </span>
      <span style={{ display: 'inline-flex', alignItems: 'center', gap: 8 }}>
        <i data-lucide="calendar" style={{ width: 14, height: 14 }}></i>
        Cohort starts {START_LABEL}
      </span>
      <span style={{ display: 'inline-flex', alignItems: 'center', gap: 8 }}>
        <i data-lucide="clock" style={{ width: 14, height: 14 }}></i>
        {APPLY_LABEL}
      </span>
    </div>;


  const Kicker = () =>
  <div style={{
    display: 'inline-flex', alignItems: 'center', gap: 10,
    padding: '8px 14px', borderRadius: 999,
    background: '#E1ECF7', color: '#2E5C8A',
    fontSize: 12, fontWeight: 700, textTransform: 'uppercase', letterSpacing: 1.4,
    marginBottom: 28
  }}>
      <span style={{
      display: 'inline-block', width: 6, height: 6, borderRadius: '50%',
      background: '#E8B225',
      animation: 'pulse 2s ease-in-out infinite'
    }} />
      The Practitioner Cohort · Spring 2026
      <style>{`@keyframes pulse {
        0%,100% { opacity:1; transform:scale(1); }
        50% { opacity:0.4; transform:scale(0.8); }
      }`}</style>
    </div>;


  // ============ VARIANT: TYPE (full-bleed typography) ============
  if (variant === 'type' || variant === 'accent') {
    return (
      <section id="top" style={{
        padding: '72px 0 96px',
        background: '#FFFFFF',
        position: 'relative', overflow: 'hidden'
      }}>
        {/* subtle grid texture */}
        <div aria-hidden="true" style={{
          position: 'absolute', inset: 0, pointerEvents: 'none',
          backgroundImage: 'radial-gradient(circle, #E1ECF7 1px, transparent 1px)',
          backgroundSize: '32px 32px', opacity: 0.5,
          maskImage: 'linear-gradient(to bottom, black 0%, transparent 80%)',
          WebkitMaskImage: 'linear-gradient(to bottom, black 0%, transparent 80%)'
        }} />

        <div className="container" style={{ position: 'relative' }}>
          <Kicker />
          <Headline />
          <Sub />
          <CTAs />
          <Meta />

          {/* Countdown ribbon */}
          <div className="hero-ribbon" style={{
            marginTop: 64, padding: '24px 32px',
            background: '#FBF9F4',
            border: '1px solid #DCE4EC',
            borderRadius: 14,
            display: 'flex', alignItems: 'center', justifyContent: 'space-between',
            flexWrap: 'wrap', gap: 20
          }}>
            <div>
              <div style={{ fontSize: 11, fontWeight: 700, color: '#2E5C8A',
                textTransform: 'uppercase', letterSpacing: 1.4 }}>
                Applications close
              </div>
              <div style={{ fontFamily: '"Space Grotesk"', fontSize: 22, fontWeight: 600,
                color: '#0E1B2E', marginTop: 4 }}>20 May 2026 — 23:59 BST

              </div>
            </div>
            <HeroCountdown targetISO={APPLY_BY} />
          </div>
          <style>{`
            @media (max-width: 760px) {
              .hero-ribbon { margin-top: 40px !important; padding: 20px !important; }
            }
          `}</style>
        </div>
      </section>);

  }

  // ============ VARIANT: IMAGE ============
  return (
    <section id="top" style={{ padding: '72px 0 96px', background: '#FFFFFF' }}>
      <div className="container hero-image-grid" style={{
        display: 'grid', gridTemplateColumns: '1.3fr 1fr', gap: 64, alignItems: 'center'
      }}>
        <div>
          <Kicker />
          <Headline />
          <Sub />
          <CTAs />
          <Meta />
        </div>
        <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 24 }}>
          <div style={{
            width: '100%', aspectRatio: '1', borderRadius: 24,
            background: 'linear-gradient(135deg, #6FA8DC, #2E5C8A)',
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            boxShadow: 'rgba(46,92,138,0.24) 0px 24px 48px',
            position: 'relative', overflow: 'hidden'
          }}>
            <img src="assets/ai-literacy-lab-logo.png"
            style={{ width: '68%', borderRadius: 16,
              boxShadow: 'rgba(0,0,0,0.18) 0px 12px 32px' }} />
          </div>
          <HeroCountdown targetISO={APPLY_BY} />
        </div>
      </div>
      <style>{`
        @media (max-width: 880px) {
          .hero-image-grid { grid-template-columns: 1fr !important; gap: 40px !important; }
        }
      `}</style>
    </section>);

};

window.Hero = Hero;