// DashboardPage.jsx — The Club Tennis Coach Dashboard
const DashboardPage = ({ onNavigate }) => {
  const today = new Date();
  const dayNames = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
  const todayName = dayNames[today.getDay()];

  const sessionMap = {
    Monday: { type: 'Regular Group', color: '#FF2D8A' },
    Tuesday: { type: 'L5 Group + Blast Movement', color: '#39FF14' },
    Wednesday: { type: 'Regular Group', color: '#FF2D8A' },
    Thursday: { type: 'L5 Group', color: '#39FF14' },
    Friday: { type: 'L5 Group', color: '#39FF14' },
    Saturday: { type: 'Regular Group', color: '#FF2D8A' },
    Sunday: null,
  };
  const todaySession = sessionMap[todayName];

  const players = [
    { name: 'Mia Chen', tier: 'Unlimited', payment: 'Paid', waiver: 'Signed', waiverExp: '2026-08-12', status: 'Active', present: false, tournament: true, ustaRating: '4.5' },
    { name: 'Jordan Park', tier: 'Monthly', payment: 'Paid', waiver: 'Signed', waiverExp: '2026-11-04', status: 'Active', present: false, tournament: false },
    { name: 'Ethan Rivera', tier: 'Drop-In', payment: 'Pending', waiver: 'Signed', waiverExp: '2026-05-20', status: 'Active', present: false, tournament: false },
    { name: 'Sofia Andrade', tier: 'Unlimited', payment: 'Paid', waiver: 'Not Signed', waiverExp: null, status: 'Active', present: false, tournament: true, ustaRating: '5.0' },
    { name: 'Caleb Williams', tier: 'Monthly', payment: 'Failed', waiver: 'Signed', waiverExp: '2026-09-30', status: 'Active', present: false, tournament: false, failedDays: 3 },
    { name: 'Ava Thompson', tier: 'Unlimited', payment: 'Paid', waiver: 'Signed', waiverExp: '2026-05-10', status: 'Active', present: false, tournament: true, ustaRating: '4.5' },
    { name: 'Noah Patel', tier: 'Monthly', payment: 'Paid', waiver: 'Signed', waiverExp: '2027-01-15', status: 'Paused', present: false, tournament: false },
    { name: 'Lily Garcia', tier: 'Drop-In', payment: 'Paid', waiver: 'Not Signed', waiverExp: null, status: 'Active', present: false, tournament: false },
    { name: 'Marcus Lee', tier: 'Unlimited', payment: 'Paid', waiver: 'Signed', waiverExp: '2026-12-08', status: 'Active', present: false, tournament: true, ustaRating: '4.0' },
    { name: 'Zoe Kim', tier: 'Monthly', payment: 'Failed', waiver: 'Signed', waiverExp: '2026-04-30', status: 'Active', present: false, tournament: false, failedDays: 6 },
  ];

  const [attendance, setAttendance] = React.useState(players.map(p => ({ ...p })));
  const [showAlert, setShowAlert] = React.useState(null);

  const toggleAttend = (i) => {
    const next = [...attendance];
    next[i].present = !next[i].present;
    setAttendance(next);
  };

  const paymentBadge = (status) => {
    const map = { Paid: ['#39FF14', 'rgba(57,255,20,0.1)'], Overdue: ['#FF2D8A', 'rgba(255,45,138,0.1)'], Failed: ['#FF2D8A', 'rgba(255,45,138,0.1)'], Pending: ['#F5A623', 'rgba(245,166,35,0.1)'] };
    const [color, bg] = map[status] || ['#888', '#1A1A1A'];
    return <span style={{ fontFamily: "'Space Mono',monospace", fontSize: 9, letterSpacing: '1.5px', textTransform: 'uppercase', color, background: bg, border: `1px solid ${color}33`, padding: '3px 8px', borderRadius: 2 }}>{status}</span>;
  };

  const statusBadge = (status) => {
    const map = { Active: ['#39FF14','rgba(57,255,20,0.08)'], Paused: ['#F5A623','rgba(245,166,35,0.08)'], Comped: ['#39FF14','rgba(57,255,20,0.08)'], Cancelled: ['#888','#1A1A1A'] };
    const [color, bg] = map[status] || ['#888','#1A1A1A'];
    return <span style={{ fontFamily: "'Space Mono',monospace", fontSize: 9, letterSpacing: '1.5px', textTransform: 'uppercase', color, background: bg, border: `1px solid ${color}33`, padding: '3px 8px', borderRadius: 2 }}>{status}</span>;
  };

  const daysUntil = (iso) => {
    if (!iso) return null;
    const diff = Math.round((new Date(iso) - new Date()) / 86400000);
    return diff;
  };

  const waiverBadge = (status) => {
    const signed = status === 'Signed';
    return <span style={{ fontFamily: "'Space Mono',monospace", fontSize: 9, letterSpacing: '1.5px', textTransform: 'uppercase', color: signed ? '#39FF14' : '#FF2D8A', background: signed ? 'rgba(57,255,20,0.1)' : 'rgba(255,45,138,0.1)', border: `1px solid ${signed ? '#39FF14' : '#FF2D8A'}33`, padding: '3px 8px', borderRadius: 2 }}>{status}</span>;
  };

  const upcomingDays = [
    { day: 'Mon', session: 'Regular', count: 9, color: '#FF2D8A' },
    { day: 'Tue', session: 'L5 + Blast', count: 7, color: '#39FF14' },
    { day: 'Wed', session: 'Regular', count: 8, color: '#FF2D8A' },
    { day: 'Thu', session: 'L5', count: 6, color: '#39FF14' },
    { day: 'Fri', session: 'L5', count: 10, color: '#39FF14' },
    { day: 'Sat', session: 'Regular', count: 9, color: '#FF2D8A' },
    { day: 'Sun', session: null, count: 0, color: '#333' },
  ];

  return (
    <div style={{ background: '#0A0A0A', fontFamily: "'Outfit',sans-serif", minHeight: '100vh' }}>
      {/* Top Bar */}
      <div className="dash-topbar" style={{ background: '#111111', borderBottom: '1px solid #2A2A2A', padding: '0 48px', height: 64, display: 'flex', alignItems: 'center', justifyContent: 'space-between', position: 'sticky', top: 0, zIndex: 100 }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 24 }}>
          <img src="images/logo/club-tennis-logo.png" alt="The Club Tennis" style={{ height: 32, width: 'auto', display: 'block', filter: 'invert(1)' }} />
          <div style={{ width: 1, height: 24, background: '#2A2A2A' }}></div>
          <span style={{ fontFamily: "'Space Mono',monospace", fontSize: 11, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#888' }}>Coach Dashboard</span>
        </div>
        <div style={{ display: 'flex', alignItems: 'center', gap: 20 }}>
          <span style={{ fontFamily: "'Space Mono',monospace", fontSize: 11, color: '#888', letterSpacing: '1px' }}>Logged in as <span style={{ color: '#F5F5F5' }}>Bo Hardt</span></span>
          <button onClick={() => onNavigate('home')} style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', background: 'transparent', border: '1px solid #2A2A2A', color: '#AAAAAA', padding: '8px 14px', cursor: 'pointer' }}>Logout</button>
        </div>
      </div>

      <div className="dash-body" style={{ padding: '40px 48px' }}>
        {/* Alert banner */}
        {showAlert && (
          <div style={{ background: '#1A0A10', border: '1px solid #FF2D8A', borderRadius: 8, padding: '16px 20px', marginBottom: 24, display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
            <span style={{ fontFamily: "'Outfit',sans-serif", fontSize: 14, color: '#F5F5F5' }}>✓ {showAlert} sent to all registered families.</span>
            <button onClick={() => setShowAlert(null)} style={{ background: 'none', border: 'none', color: '#888', cursor: 'pointer', fontSize: 18 }}>×</button>
          </div>
        )}

        {/* Bo header */}
        <div className="dash-bo-header" style={{ display: 'flex', alignItems: 'center', gap: 24, marginBottom: 36, background: '#111111', border: '1px solid #2A2A2A', borderRadius: 8, padding: '20px 28px' }}>
          <div style={{ width: 64, height: 64, borderRadius: '50%', overflow: 'hidden', border: '2px solid #FF2D8A', flexShrink: 0 }}>
            <img src="images/coaches/bo-hardt.png" alt="Bo Hardt" style={{ width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 20%' }} />
          </div>
          <div>
            <div style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 900, fontSize: 22, color: '#F5F5F5', letterSpacing: '-0.5px' }}>Welcome back, Bo.</div>
            <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 11, color: '#888', letterSpacing: '1.5px', textTransform: 'uppercase', marginTop: 4 }}>Head Coach & Founder, The Club Tennis</div>
          </div>
          <div style={{ marginLeft: 'auto', fontFamily: "'Space Mono',monospace", fontSize: 11, color: '#555', letterSpacing: '1px' }}>
            {today.toLocaleDateString('en-US', { weekday: 'long', month: 'long', day: 'numeric' })}
          </div>
        </div>

        {/* Quick Actions */}
        <div className="dash-quick-actions" style={{ display: 'flex', gap: 12, marginBottom: 36 }}>
          <button onClick={() => setShowAlert('Rain cancellation')} style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 700, fontSize: 14, textTransform: 'uppercase', background: '#1A0505', border: '2px solid #FF2D8A', color: '#FF2D8A', padding: '14px 24px', cursor: 'pointer', borderRadius: 4, display: 'flex', alignItems: 'center', gap: 10 }}>
            <span>⚠</span> Send Rain Cancellation
          </button>
          <button onClick={() => setShowAlert('Announcement')} style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 700, fontSize: 14, textTransform: 'uppercase', background: '#111111', border: '1px solid #2A2A2A', color: '#AAAAAA', padding: '14px 24px', cursor: 'pointer', borderRadius: 4 }}>
            Send Announcement
          </button>
        </div>

        {/* Summary Cards */}
        <div className="dash-cards-4" style={{ display: 'grid', gridTemplateColumns: 'repeat(4,1fr)', gap: 16, marginBottom: 16 }}>
          {[
            { label: 'Active Players', value: '50', sub: 'Total roster', color: '#F5F5F5' },
            { label: 'Revenue This Month', value: '$18,240', sub: 'All tiers combined', color: '#39FF14' },
            { label: 'Failed Payments', value: '2', sub: 'Cards declined, needs review', color: '#FF2D8A' },
            { label: 'Unsigned Waivers', value: '2', sub: 'Action required', color: '#F5A623' },
          ].map((card, i) => (
            <div key={i} style={{ background: '#111111', border: '1px solid #2A2A2A', borderRadius: 8, padding: '24px 20px' }}>
              <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#888', marginBottom: 8 }}>{card.label}</div>
              <div style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 900, fontSize: 36, letterSpacing: '-1.5px', color: card.color, lineHeight: 1, marginBottom: 6 }}>{card.value}</div>
              <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, color: '#555', letterSpacing: '1px' }}>{card.sub}</div>
            </div>
          ))}
        </div>

        {/* MRR / Stripe Row */}
        <div className="dash-cards-4" style={{ display: 'grid', gridTemplateColumns: 'repeat(4,1fr)', gap: 16, marginBottom: 36 }}>
          {[
            { label: 'MRR', value: '$15,840', sub: '+$720 vs last month', color: '#39FF14', tag: 'Stripe' },
            { label: 'New This Month', value: '4', sub: '3 Monthly · 1 Unlimited', color: '#F5F5F5', tag: 'Stripe' },
            { label: 'Churn', value: '1', sub: '−$360 MRR lost', color: '#FF2D8A', tag: 'Stripe' },
            { label: 'Renewals (7d)', value: '11', sub: 'Auto-charging this week', color: '#F5F5F5', tag: 'Stripe' },
          ].map((card, i) => (
            <div key={i} style={{ background: '#111111', border: '1px solid #2A2A2A', borderRadius: 8, padding: '20px', position: 'relative' }}>
              <span style={{ position: 'absolute', top: 12, right: 12, fontFamily: "'Space Mono',monospace", fontSize: 8, letterSpacing: '1.5px', color: '#39FF14', border: '1px solid rgba(57,255,20,0.3)', padding: '2px 6px', borderRadius: 2 }}>{card.tag}</span>
              <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#888', marginBottom: 8 }}>{card.label}</div>
              <div style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 900, fontSize: 28, letterSpacing: '-1px', color: card.color, lineHeight: 1, marginBottom: 6 }}>{card.value}</div>
              <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, color: '#555', letterSpacing: '0.5px' }}>{card.sub}</div>
            </div>
          ))}
        </div>

        {/* Failed Payments Queue + Waiver Expirations side-by-side */}
        <div className="dash-split-2" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 24, marginBottom: 36 }}>
          {/* Failed Payments */}
          <div style={{ background: '#111111', border: '1px solid #FF2D8A', borderRadius: 8, overflow: 'hidden' }}>
            <div style={{ padding: '20px 24px', borderBottom: '1px solid #2A2A2A', background: 'rgba(255,45,138,0.05)' }}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 4 }}>
                <span style={{ color: '#FF2D8A' }}>⚠</span>
                <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#FF2D8A' }}>Failed Payments</div>
              </div>
              <div style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 800, fontSize: 16, color: '#F5F5F5' }}>2 cards declined</div>
            </div>
            {attendance.filter(p => p.payment === 'Failed').map((p, i) => (
              <div key={i} style={{ padding: '14px 24px', borderBottom: '1px solid #1A1A1A', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
                <div>
                  <div style={{ fontFamily: "'Outfit',sans-serif", fontSize: 14, color: '#F5F5F5', fontWeight: 600 }}>{p.name}</div>
                  <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, color: '#888', letterSpacing: '1px', marginTop: 2 }}>
                    {p.tier} · ${p.tier === 'Unlimited' ? '1,120' : p.tier === 'Monthly' ? '360' : '100'} · Failed {p.failedDays}d ago
                  </div>
                </div>
                <div style={{ display: 'flex', gap: 6 }}>
                  <button style={{ fontFamily: "'Space Mono',monospace", fontSize: 9, letterSpacing: '1px', textTransform: 'uppercase', background: 'transparent', border: '1px solid #39FF14', color: '#39FF14', padding: '6px 10px', cursor: 'pointer', borderRadius: 2 }}>Retry</button>
                  <button style={{ fontFamily: "'Space Mono',monospace", fontSize: 9, letterSpacing: '1px', textTransform: 'uppercase', background: 'transparent', border: '1px solid #2A2A2A', color: '#AAAAAA', padding: '6px 10px', cursor: 'pointer', borderRadius: 2 }}>Email</button>
                </div>
              </div>
            ))}
          </div>

          {/* Waiver Expirations */}
          <div style={{ background: '#111111', border: '1px solid #2A2A2A', borderRadius: 8, overflow: 'hidden' }}>
            <div style={{ padding: '20px 24px', borderBottom: '1px solid #2A2A2A' }}>
              <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#F5A623', marginBottom: 4 }}>Waivers</div>
              <div style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 800, fontSize: 16, color: '#F5F5F5' }}>Expiring or unsigned</div>
            </div>
            {[
              ...attendance.filter(p => p.waiver === 'Not Signed').map(p => ({ ...p, urgency: 'unsigned' })),
              ...attendance.filter(p => p.waiver === 'Signed' && daysUntil(p.waiverExp) !== null && daysUntil(p.waiverExp) < 60).map(p => ({ ...p, urgency: 'expiring' })),
            ].slice(0, 5).map((p, i) => {
              const days = daysUntil(p.waiverExp);
              return (
                <div key={i} style={{ padding: '14px 24px', borderBottom: '1px solid #1A1A1A', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
                  <div>
                    <div style={{ fontFamily: "'Outfit',sans-serif", fontSize: 14, color: '#F5F5F5', fontWeight: 600 }}>{p.name}</div>
                    <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, color: '#888', letterSpacing: '1px', marginTop: 2 }}>
                      {p.urgency === 'unsigned' ? 'Never signed' : (days < 0 ? `Expired ${-days}d ago` : `Expires in ${days}d`)}
                    </div>
                  </div>
                  <button style={{ fontFamily: "'Space Mono',monospace", fontSize: 9, letterSpacing: '1px', textTransform: 'uppercase', background: 'transparent', border: '1px solid #F5A623', color: '#F5A623', padding: '6px 10px', cursor: 'pointer', borderRadius: 2 }}>Send Link</button>
                </div>
              );
            })}
          </div>
        </div>

        <div className="dash-split-2" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 24, marginBottom: 36 }}>
          {/* Today's Session */}
          <div style={{ background: '#111111', border: '1px solid #2A2A2A', borderRadius: 8, overflow: 'hidden' }}>
            <div style={{ padding: '20px 24px', borderBottom: '1px solid #2A2A2A', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
              <div>
                <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#888', marginBottom: 4 }}>Today: {todayName}</div>
                <div style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 800, fontSize: 18, color: '#F5F5F5' }}>
                  {todaySession ? todaySession.type : 'No Session'}
                </div>
              </div>
              {todaySession && (
                <span style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1px', color: todaySession.color, border: `1px solid ${todaySession.color}44`, background: `${todaySession.color}11`, padding: '6px 12px', borderRadius: 2 }}>5:30-7:30 PM</span>
              )}
            </div>
            <div style={{ padding: '8px 0' }}>
              <div style={{ padding: '8px 24px', fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#888' }}>
                Attendance ({attendance.filter(p=>p.present).length}/{attendance.length})
              </div>
              {attendance.map((p, i) => (
                <div key={i} onClick={() => toggleAttend(i)} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '10px 24px', cursor: 'pointer', background: p.present ? 'rgba(57,255,20,0.04)' : 'transparent', borderLeft: p.present ? '3px solid #39FF14' : '3px solid transparent', transition: 'all 120ms' }}>
                  <div style={{ width: 18, height: 18, border: `2px solid ${p.present ? '#39FF14' : '#2A2A2A'}`, borderRadius: 3, background: p.present ? '#39FF14' : 'transparent', display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0, transition: 'all 120ms' }}>
                    {p.present && <span style={{ color: '#0A0A0A', fontSize: 11, fontWeight: 900, lineHeight: 1 }}>✓</span>}
                  </div>
                  <span style={{ fontFamily: "'Outfit',sans-serif", fontSize: 14, color: p.present ? '#F5F5F5' : '#AAAAAA' }}>{p.name}</span>
                  <span style={{ marginLeft: 'auto', fontFamily: "'Space Mono',monospace", fontSize: 9, color: '#555', letterSpacing: '1px', textTransform: 'uppercase' }}>{p.tier}</span>
                </div>
              ))}
            </div>
          </div>

          {/* Upcoming Week */}
          <div style={{ background: '#111111', border: '1px solid #2A2A2A', borderRadius: 8, overflow: 'hidden' }}>
            <div style={{ padding: '20px 24px', borderBottom: '1px solid #2A2A2A' }}>
              <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#888', marginBottom: 4 }}>Upcoming</div>
              <div style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 800, fontSize: 18, color: '#F5F5F5' }}>This Week</div>
            </div>
            <div>
              {upcomingDays.map((d, i) => (
                <div key={i} style={{ display: 'flex', alignItems: 'center', padding: '14px 24px', borderBottom: '1px solid #1A1A1A', opacity: d.session ? 1 : 0.4 }}>
                  <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 11, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#888', width: 36 }}>{d.day}</div>
                  <div style={{ flex: 1 }}>
                    {d.session
                      ? <span style={{ fontFamily: "'Outfit',sans-serif", fontSize: 14, color: d.color, fontWeight: 600 }}>{d.session}</span>
                      : <span style={{ fontFamily: "'Space Mono',monospace", fontSize: 11, color: '#555' }}>REST</span>
                    }
                  </div>
                  {d.session && (
                    <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
                      <div style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 800, fontSize: 16, color: '#F5F5F5' }}>{d.count}</div>
                      <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 9, color: '#555', letterSpacing: '1px', textTransform: 'uppercase' }}>players</div>
                    </div>
                  )}
                </div>
              ))}
            </div>
          </div>
        </div>

        {/* Full Roster Table */}
        <div className="dash-card" style={{ background: '#111111', border: '1px solid #2A2A2A', borderRadius: 8, overflow: 'hidden', marginBottom: 36 }}>
          <div style={{ padding: '20px 24px', borderBottom: '1px solid #2A2A2A', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
            <div style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 800, fontSize: 18, color: '#F5F5F5' }}>Roster Overview</div>
            <button style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', background: 'transparent', border: '1px solid #2A2A2A', color: '#AAAAAA', padding: '8px 14px', cursor: 'pointer', borderRadius: 2 }}>Export CSV</button>
          </div>
          <table className="dash-table" style={{ width: '100%', borderCollapse: 'collapse' }}>
            <thead>
              <tr style={{ borderBottom: '1px solid #2A2A2A' }}>
                {['Player','Tier','Status','Payment','Waiver','Actions'].map(h => (
                  <th key={h} style={{ padding: '12px 24px', textAlign: 'left', fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#555', fontWeight: 400 }}>{h}</th>
                ))}
              </tr>
            </thead>
            <tbody>
              {attendance.map((p, i) => (
                <tr key={i} style={{ borderBottom: '1px solid #1A1A1A', transition: 'background 120ms' }}
                  onMouseEnter={e => e.currentTarget.style.background = '#1A1A1A'}
                  onMouseLeave={e => e.currentTarget.style.background = 'transparent'}>
                  <td style={{ padding: '14px 24px', fontFamily: "'Outfit',sans-serif", fontSize: 14, color: '#F5F5F5', fontWeight: 500 }}>{p.name}</td>
                  <td style={{ padding: '14px 24px', fontFamily: "'Space Mono',monospace", fontSize: 11, color: '#888', letterSpacing: '1px' }}>{p.tier}</td>
                  <td style={{ padding: '14px 24px' }}>{statusBadge(p.status)}</td>
                  <td style={{ padding: '14px 24px' }}>{paymentBadge(p.payment)}</td>
                  <td style={{ padding: '14px 24px' }}>{waiverBadge(p.waiver)}</td>
                  <td style={{ padding: '14px 24px' }}>
                    <div style={{ display: 'flex', gap: 6 }}>
                      <button title="Pause subscription" style={{ fontFamily: "'Space Mono',monospace", fontSize: 9, letterSpacing: '1px', textTransform: 'uppercase', background: 'transparent', border: '1px solid #2A2A2A', color: '#AAAAAA', padding: '5px 9px', cursor: 'pointer', borderRadius: 2 }}>{p.status === 'Paused' ? 'Resume' : 'Pause'}</button>
                      <button title="Refund last charge" style={{ fontFamily: "'Space Mono',monospace", fontSize: 9, letterSpacing: '1px', textTransform: 'uppercase', background: 'transparent', border: '1px solid #2A2A2A', color: '#AAAAAA', padding: '5px 9px', cursor: 'pointer', borderRadius: 2 }}>Refund</button>
                      <button title="Comp player" style={{ fontFamily: "'Space Mono',monospace", fontSize: 9, letterSpacing: '1px', textTransform: 'uppercase', background: 'transparent', border: '1px solid #2A2A2A', color: '#AAAAAA', padding: '5px 9px', cursor: 'pointer', borderRadius: 2 }}>Comp</button>
                    </div>
                  </td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>

        {/* Spain Camp Signups */}
        {(() => {
          const spainSignups = [
            { player: 'Ava Thompson', age: 14, parent: 'Lisa Thompson', email: 'parent1@example.com', phone: '(310) 555-0100', usta: '4.5', depositPaid: true },
            { player: 'Marcus Lee', age: 16, parent: 'David Lee', email: 'parent2@example.com', phone: '(818) 555-0100', usta: '4.0', depositPaid: false },
            { player: 'Sofia Andrade', age: 13, parent: 'Carlos Andrade', email: 'parent3@example.com', phone: '(424) 555-0100', usta: '5.0', depositPaid: true },
          ];
          return (
            <div className="dash-card" style={{ background: '#111111', border: '1px solid #2A2A2A', borderRadius: 8, overflow: 'hidden', marginBottom: 36 }}>
              <div style={{ padding: '20px 24px', borderBottom: '1px solid #2A2A2A', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
                <div>
                  <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#FF2D8A', marginBottom: 4 }}>Summer 2026</div>
                  <div style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 800, fontSize: 18, color: '#F5F5F5' }}>Spain Camp Signups ({spainSignups.length} / 6 spots)</div>
                </div>
                <div style={{ display: 'flex', gap: 8 }}>
                  <div style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 900, fontSize: 24, color: '#FF2D8A' }}>{spainSignups.filter(s => s.depositPaid).length}</div>
                  <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, color: '#888', letterSpacing: '1px', textTransform: 'uppercase', alignSelf: 'flex-end', marginBottom: 3 }}>deposits paid</div>
                </div>
              </div>
              <table className="dash-table" style={{ width: '100%', borderCollapse: 'collapse' }}>
                <thead>
                  <tr style={{ borderBottom: '1px solid #2A2A2A' }}>
                    {['Player','Age','Parent','Email','USTA','Deposit'].map(h => (
                      <th key={h} style={{ padding: '12px 24px', textAlign: 'left', fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#555', fontWeight: 400 }}>{h}</th>
                    ))}
                  </tr>
                </thead>
                <tbody>
                  {spainSignups.map((s, i) => (
                    <tr key={i} style={{ borderBottom: '1px solid #1A1A1A' }}
                      onMouseEnter={e => e.currentTarget.style.background = '#1A1A1A'}
                      onMouseLeave={e => e.currentTarget.style.background = 'transparent'}>
                      <td style={{ padding: '14px 24px', fontFamily: "'Outfit',sans-serif", fontSize: 14, color: '#F5F5F5', fontWeight: 500 }}>{s.player}</td>
                      <td style={{ padding: '14px 24px', fontFamily: "'Space Mono',monospace", fontSize: 12, color: '#AAAAAA' }}>{s.age}</td>
                      <td style={{ padding: '14px 24px', fontFamily: "'Outfit',sans-serif", fontSize: 14, color: '#AAAAAA' }}>{s.parent}</td>
                      <td style={{ padding: '14px 24px', fontFamily: "'Space Mono',monospace", fontSize: 11, color: '#888' }}>{s.email}</td>
                      <td style={{ padding: '14px 24px', fontFamily: "'Space Mono',monospace", fontSize: 12, color: '#39FF14', letterSpacing: '1px' }}>{s.usta}</td>
                      <td style={{ padding: '14px 24px' }}>
                        <span style={{ fontFamily: "'Space Mono',monospace", fontSize: 9, letterSpacing: '1.5px', textTransform: 'uppercase', color: s.depositPaid ? '#39FF14' : '#F5A623', background: s.depositPaid ? 'rgba(57,255,20,0.1)' : 'rgba(245,166,35,0.1)', border: `1px solid ${s.depositPaid ? '#39FF14' : '#F5A623'}33`, padding: '3px 8px', borderRadius: 2 }}>
                          {s.depositPaid ? 'Paid' : 'Pending'}
                        </span>
                      </td>
                    </tr>
                  ))}
                </tbody>
              </table>
              <div style={{ padding: '16px 24px', borderTop: '1px solid #1A1A1A', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
                <span style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, color: '#555', letterSpacing: '1px' }}>{6 - spainSignups.length} spots remaining</span>
                <button style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', background: 'transparent', border: '1px solid #FF2D8A', color: '#FF2D8A', padding: '8px 14px', cursor: 'pointer', borderRadius: 2 }}>Email All Signups</button>
              </div>
            </div>
          );
        })()}

        {/* Tournament Team Roster */}
        <div className="dash-card" style={{ background: '#111111', border: '1px solid #2A2A2A', borderRadius: 8, overflow: 'hidden', marginBottom: 36 }}>
          <div style={{ padding: '20px 24px', borderBottom: '1px solid #2A2A2A', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
            <div>
              <div style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#39FF14', marginBottom: 4 }}>Tournament Team</div>
              <div style={{ fontFamily: "'Outfit',sans-serif", fontWeight: 800, fontSize: 18, color: '#F5F5F5' }}>USTA Travel Roster ({attendance.filter(p => p.tournament).length} players)</div>
            </div>
            <button style={{ fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', background: 'transparent', border: '1px solid #39FF14', color: '#39FF14', padding: '8px 14px', cursor: 'pointer', borderRadius: 2 }}>Email Team</button>
          </div>
          <table className="dash-table" style={{ width: '100%', borderCollapse: 'collapse' }}>
            <thead>
              <tr style={{ borderBottom: '1px solid #2A2A2A' }}>
                {['Player','USTA Rating','Tier','Season Fee'].map(h => (
                  <th key={h} style={{ padding: '12px 24px', textAlign: 'left', fontFamily: "'Space Mono',monospace", fontSize: 10, letterSpacing: '1.5px', textTransform: 'uppercase', color: '#555', fontWeight: 400 }}>{h}</th>
                ))}
              </tr>
            </thead>
            <tbody>
              {attendance.filter(p => p.tournament).map((p, i) => (
                <tr key={i} style={{ borderBottom: '1px solid #1A1A1A' }}>
                  <td style={{ padding: '14px 24px', fontFamily: "'Outfit',sans-serif", fontSize: 14, color: '#F5F5F5', fontWeight: 500 }}>{p.name}</td>
                  <td style={{ padding: '14px 24px', fontFamily: "'Space Mono',monospace", fontSize: 12, color: '#39FF14', letterSpacing: '1px' }}>{p.ustaRating}</td>
                  <td style={{ padding: '14px 24px', fontFamily: "'Space Mono',monospace", fontSize: 11, color: '#888', letterSpacing: '1px' }}>{p.tier}</td>
                  <td style={{ padding: '14px 24px', fontFamily: "'Space Mono',monospace", fontSize: 12, color: '#39FF14' }}>$500 paid</td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>
      </div>
    </div>
  );
};

Object.assign(window, { DashboardPage });
