// Positions come from the design mockup (1440-wide artboard coordinates).
// [x, y, color, animation delay] for each bulb on the light string.
const NBC_BULBS = [
  [41, 40, '#FFC83D', -0.0],
  [120, 52, '#FF6B6B', -0.37],
  [199, 40, '#7BE0AD', -0.74],
  [281, 40, '#8FD3FF', -1.11],
  [360, 52, '#FFE9A8', -1.48],
  [439, 40, '#FFC83D', -1.85],
  [521, 40, '#FF6B6B', -0.22],
  [600, 52, '#7BE0AD', -0.59],
  [679, 40, '#8FD3FF', -0.96],
  [761, 40, '#FFE9A8', -1.33],
  [840, 52, '#FFC83D', -1.7],
  [919, 40, '#FF6B6B', -0.07],
  [1001, 40, '#7BE0AD', -0.44],
  [1080, 52, '#8FD3FF', -0.81],
  [1159, 40, '#FFE9A8', -1.18],
  [1241, 40, '#FFC83D', -1.55],
  [1320, 52, '#FF6B6B', -1.92],
  [1399, 40, '#7BE0AD', -0.29],
];
// [x, y, radius, opacity, animation delay] for the drifting snowflakes.
const NBC_FLAKES = [
  [673, 244, 3.0, 0.35, -3.9],
  [1107, 186, 2.5, 0.5, -3.5],
  [86, 178, 3.0, 0.5, -2.5],
  [195, 654, 3.0, 0.35, -0.4],
  [467, 735, 4.0, 0.9, -5.7],
  [111, 316, 1.5, 0.5, -3.3],
  [603, 519, 2.0, 0.7, -3.2],
  [1157, 788, 2.0, 0.5, -0.6],
  [772, 189, 4.0, 0.35, -4.3],
  [1277, 300, 3.0, 0.9, -4.1],
  [653, 566, 4.0, 0.7, -5.5],
  [623, 344, 2.0, 0.5, -4.2],
  [177, 678, 2.5, 0.7, -3.2],
  [929, 384, 4.0, 0.35, -5.9],
  [1058, 518, 2.0, 0.5, -4.5],
  [1011, 521, 1.5, 0.35, -5.8],
  [1152, 676, 2.5, 0.7, -2.0],
  [1227, 598, 4.0, 0.35, -4.8],
  [201, 366, 3.0, 0.35, -4.2],
  [134, 738, 2.5, 0.9, -3.9],
  [592, 723, 3.0, 0.7, -5.3],
  [56, 562, 2.5, 0.35, -1.0],
  [1021, 150, 2.0, 0.5, -4.6],
  [517, 497, 3.0, 0.9, -5.5],
  [175, 260, 3.0, 0.7, -2.4],
  [290, 530, 4.0, 0.9, -1.7],
  [379, 270, 2.0, 0.5, -1.4],
  [34, 586, 4.0, 0.7, -1.1],
  [18, 239, 3.0, 0.7, -3.2],
  [945, 706, 4.0, 0.9, -2.4],
  [817, 196, 3.0, 0.35, -3.8],
  [400, 158, 2.0, 0.35, -2.6],
];
// [left, peak x, peak y, right] for each pine tree silhouette.
const NBC_TREES = [
  [-10, 7, 23, 24],
  [27, 40, 38, 52],
  [61, 74, 35, 88],
  [129, 142, 38, 154],
  [186, 197, 43, 209],
  [224, 239, 31, 253],
  [282, 295, 35, 309],
  [332, 349, 22, 366],
  [389, 408, 14, 428],
  [430, 443, 37, 456],
  [495, 514, 15, 533],
  [559, 578, 14, 598],
  [612, 624, 39, 637],
  [655, 668, 38, 680],
  [710, 725, 28, 741],
  [774, 788, 34, 802],
  [841, 852, 43, 864],
  [888, 905, 21, 923],
  [931, 942, 43, 954],
  [998, 1014, 25, 1030],
  [1037, 1052, 28, 1068],
  [1104, 1121, 21, 1139],
  [1148, 1165, 22, 1182],
  [1196, 1216, 12, 1236],
  [1251, 1266, 30, 1281],
  [1297, 1312, 29, 1327],
  [1356, 1371, 30, 1386],
  [1402, 1422, 13, 1441],
];

// festive-hero.jsx — "Night Before Christmas" home hero (from the design mockup).
// Shown instead of the regular hero only while the winter theme is on (see winter-snow.js).

function nbcInjectStyles() {
  if (document.getElementById('nbc-hero-css')) return;
  const s = document.createElement('style');
  s.id = 'nbc-hero-css';
  s.textContent = `
    @keyframes nbcTwinkle { 0%,100% { opacity: 1 } 50% { opacity: .45 } }
    @keyframes nbcDrift { 0% { transform: translateY(0) } 100% { transform: translateY(14px) } }
    .nbc-bulb { animation: nbcTwinkle 2.2s ease-in-out infinite }
    .nbc-flake { animation: nbcDrift 5s ease-in-out infinite alternate }
    .nbc-cta:hover { background: #ffffff !important; color: #0B2646 !important }
    @media (prefers-reduced-motion: reduce) { .nbc-bulb, .nbc-flake { animation: none } }
  `;
  document.head.appendChild(s);
}

// =============================================================== FESTIVE HERO
function HeroFestive({ fonts, setPage }) {
  const mobile = useMobile();
  const navy = '#0B2646';
  const gold = '#FFC83D';
  const red = '#C8102E';
  React.useEffect(nbcInjectStyles, []);
  const ev = UPCOMING_EVENTS[0];

  // On phones the light string and trees get a fixed height so they crop in from the middle instead of shrinking to dots.
  const stripH = mobile ? 56 : 'auto';

  return (
    <section style={{ position: 'relative', background: navy, color: '#ffffff', overflow: 'hidden' }}>
      {/* drifting snowflakes */}
      <svg aria-hidden="true" viewBox="0 0 1440 860" preserveAspectRatio="xMidYMin slice" style={{ position: 'absolute', left: 0, top: 0, width: '100%', height: '100%', pointerEvents: 'none' }}>
        {NBC_FLAKES.map(([x, y, r, o, d], i) => (
          <circle key={i} className="nbc-flake" style={{ animationDelay: `${d}s` }} cx={x} cy={y} r={r} fill="#fff" opacity={o} />
        ))}
      </svg>

      {/* string of lights hanging from the header */}
      <svg aria-hidden="true" viewBox="0 0 1440 90" preserveAspectRatio="xMidYMin slice" style={{ position: 'absolute', left: 0, top: 0, width: '100%', height: stripH, display: 'block', pointerEvents: 'none' }}>
        <path d="M0,8 Q120,64 240,8 Q360,64 480,8 Q600,64 720,8 Q840,64 960,8 Q1080,64 1200,8 Q1320,64 1440,8" fill="none" stroke="#06162B" strokeWidth="3" />
        {NBC_BULBS.map(([x, y, c, d], i) => (
          <g key={i} className="nbc-bulb" style={{ animationDelay: `${d}s` }}>
            <circle cx={x} cy={y} r="15" fill={c} opacity=".28" />
            <rect x={x - 3} y={y - 17} width="6" height="7" fill="#06162B" />
            <ellipse cx={x} cy={y - 2} rx="6" ry="9" fill={c} />
          </g>
        ))}
      </svg>

      <div style={{
        position: 'relative', boxSizing: 'border-box',
        padding: mobile ? '64px 20px 96px' : '72px 48px 150px',
        display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: mobile ? '40px 32px' : '48px 64px',
      }}>
        <div style={{ flex: '1 1 560px', minWidth: 0 }}>
          <h1 style={{
            margin: 0, fontFamily: fonts.head, fontWeight: 900,
            fontSize: 'clamp(56px, 10.4vw, 150px)', lineHeight: .9, letterSpacing: '-.04em', textTransform: 'uppercase',
          }}>
            <span style={{ display: 'block' }}>Beta is</span>
            <span style={{ display: 'inline-block', marginTop: 6, padding: '0 .08em 0 .06em', background: gold, color: navy, transform: 'rotate(-1.2deg)' }}>Service.</span>
          </h1>
          <p style={{ margin: mobile ? '32px 0 0' : '48px 0 0', maxWidth: 620, fontSize: mobile ? 18 : 24, lineHeight: 1.35, fontWeight: 500, color: '#DCE6F5' }}>
            We're the largest student-led organization at Hoggard. We strive to give back to the community and make the world a better place.
          </p>
        </div>

        <div style={{ flex: '0 1 560px', minWidth: mobile ? 0 : 300, width: mobile ? '100%' : undefined, position: 'relative', marginTop: mobile ? 24 : 30 }}>
          {ev && (
            <div style={{
              position: 'absolute', right: mobile ? 0 : -30, top: mobile ? -36 : -44, zIndex: 4, width: mobile ? 190 : 236, boxSizing: 'border-box',
              padding: '14px 16px 14px 18px', background: '#ffffff', color: navy, border: `3px solid ${navy}`,
              boxShadow: `0 0 0 3px ${gold}`, transform: 'rotate(3deg)', fontWeight: 800, lineHeight: 1.2,
            }}>
              <div style={{ fontSize: 11, letterSpacing: '.14em', textTransform: 'uppercase', color: '#B00D28' }}>+ Up next</div>
              <div style={{ fontSize: mobile ? 14 : 16, marginTop: 4 }}>{ev.title} · {ev.mo.charAt(0).toUpperCase() + ev.mo.slice(1).toLowerCase()} {ev.day}</div>
            </div>
          )}

          <div data-snow="box" style={{ position: 'relative', background: gold, color: navy, border: '3px solid #ffffff', boxShadow: `${mobile ? 10 : 16}px ${mobile ? 10 : 16}px 0 ${red}` }}>
            <div style={{ padding: mobile ? '68px 24px 32px' : '68px 36px 38px', textAlign: 'center' }}>
              <div style={{ fontSize: 13, fontWeight: 800, letterSpacing: '.2em', textTransform: 'uppercase' }}>Ready to volunteer?</div>
              <h2 style={{ margin: '14px 0 0', fontFamily: fonts.head, fontWeight: 900, fontSize: 'clamp(40px, 4.4vw, 60px)', lineHeight: .92, letterSpacing: '-.04em', textTransform: 'uppercase' }}>
                Sign up<br/>for an event.
              </h2>
              <button className="nbc-cta" onClick={() => setPage('signup')} style={{
                all: 'unset', cursor: 'pointer', display: 'inline-block', marginTop: 28, padding: mobile ? '15px 26px' : '18px 34px',
                background: navy, color: gold, fontFamily: fonts.head, fontWeight: 900, fontSize: mobile ? 16 : 18, letterSpacing: '.01em', textTransform: 'uppercase',
              }}>
                Event sign up →
              </button>
            </div>
            <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, minmax(0, 1fr))', borderTop: `3px solid ${navy}` }}>
              {STATS.map((s, i) => (
                <div key={i} style={{ padding: mobile ? '16px 6px 14px' : '20px 8px 18px', textAlign: 'center', borderRight: i < STATS.length - 1 ? `3px solid ${navy}` : 'none' }}>
                  <div style={{ fontFamily: fonts.head, fontWeight: 900, fontSize: mobile ? 'clamp(22px, 6vw, 30px)' : 36, letterSpacing: '-.04em' }}>
                    <CountUp to={s.value} prefix={s.prefix} suffix={s.suffix} />
                  </div>
                  <div style={{ fontSize: 11, fontWeight: 800, letterSpacing: '.1em', textTransform: 'uppercase', marginTop: 4 }}>{s.label}</div>
                </div>
              ))}
            </div>
          </div>
        </div>
      </div>

      {/* pine forest and snow bank; the bank takes the page background color so it melts into the next section */}
      <svg aria-hidden="true" viewBox="0 0 1440 90" preserveAspectRatio="xMidYMax slice" style={{ position: 'absolute', left: 0, bottom: 0, width: '100%', height: stripH, display: 'block', pointerEvents: 'none' }}>
        {NBC_TREES.map(([a, b, c, d], i) => (
          <path key={i} d={`M${a},84 L${b},${c} L${d},84 Z`} fill="#081B34" />
        ))}
        <path d="M0,78 C160,64 300,86 480,76 C660,66 800,86 980,76 C1140,67 1290,84 1440,74 L1440,90 L0,90 Z" style={{ fill: 'var(--bg, #ffffff)' }} />
      </svg>
    </section>
  );
}

Object.assign(window, { HeroFestive });
