// Admin screens: Dashboard, Users, Orders
const { useState: useStateA, useMemo: useMemoA } = React;

const fmt = (n) => '฿' + n.toLocaleString();

function AdminLayout({ active, nav, children, title, subtitle, action }) {
  const items = [
    { label: 'แดชบอร์ด', icon: 'chart', path: '/admin' },
    { label: 'ผู้ใช้', icon: 'users', path: '/admin/users' },
    { label: 'คำสั่งซื้อ', icon: 'receipt', path: '/admin/orders' },
    { label: 'สินค้า', icon: 'package', path: '/admin/products', soon: true },
    { label: 'คูปอง', icon: 'tag', path: '/admin/coupons', soon: true },
    { label: 'Analytics', icon: 'trendUp', path: '/admin/analytics', soon: true },
    { label: 'ตั้งค่า', icon: 'settings', path: '/admin/settings', soon: true },
  ];
  return (
    <div className="admin-scope" style={{ minHeight: '100vh', background: 'var(--bg)', color: 'var(--ink)', display: 'grid', gridTemplateColumns: '240px 1fr' }}>
      <aside style={{ background: 'var(--bg-2)', borderRight: '1px solid var(--line)', padding: '20px 16px', display: 'flex', flexDirection: 'column', gap: 24, position: 'sticky', top: 0, height: '100vh', overflowY: 'auto' }}>
        <button onClick={() => nav('/admin')} style={{ background: 'transparent', border: 'none', padding: '4px 8px', cursor: 'pointer', display: 'flex', alignItems: 'center', gap: 8, color: 'var(--ink)' }}>
          <svg width="22" height="22" viewBox="0 0 32 32"><rect x="3" y="3" width="26" height="26" rx="7" fill="var(--primary)"/><path d="M11 9v14M11 16l8-7M11 16l8 7" stroke="#FFFFFF" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" fill="none"/></svg>
          <div style={{ textAlign: 'left' }}>
            <div style={{ fontSize: 13.5, fontWeight: 600, letterSpacing: '-0.01em' }}>KindleStartup</div>
            <div style={{ fontSize: 11, color: 'var(--ink-3)' }}>Admin Panel</div>
          </div>
        </button>
        <nav style={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
          {items.map(it => (
            <button key={it.path} onClick={() => !it.soon && nav(it.path)} disabled={it.soon} style={{
              display: 'flex', alignItems: 'center', gap: 10,
              padding: '8px 12px', borderRadius: 8,
              background: active === it.path ? 'var(--bg-3)' : 'transparent',
              border: 'none', cursor: it.soon ? 'not-allowed' : 'pointer',
              textAlign: 'left', fontSize: 13.5,
              color: active === it.path ? 'var(--ink)' : it.soon ? 'var(--ink-3)' : 'var(--ink-2)',
              fontWeight: active === it.path ? 500 : 400,
              opacity: it.soon ? 0.7 : 1,
            }}>
              <I name={it.icon} size={15} />
              <span style={{ flex: 1 }}>{it.label}</span>
              {it.soon && <span style={{ fontSize: 10, color: 'var(--ink-3)', background: 'var(--bg-3)', padding: '2px 6px', borderRadius: 4 }}>Phase 2</span>}
            </button>
          ))}
        </nav>
        <div style={{ marginTop: 'auto', borderTop: '1px solid var(--line)', paddingTop: 16, display: 'flex', alignItems: 'center', gap: 10 }}>
          <Avatar name="Admin" size={32} />
          <div style={{ flex: 1, minWidth: 0 }}>
            <div style={{ fontSize: 12.5, fontWeight: 500 }}>Admin</div>
            <div style={{ fontSize: 11, color: 'var(--ink-3)' }}>admin@kindlestartup.com</div>
          </div>
          <button onClick={() => nav('/dashboard')} title="กลับฝั่ง User" style={{ background: 'transparent', border: 'none', cursor: 'pointer', color: 'var(--ink-3)', padding: 4 }}>
            <I name="logout" size={14} />
          </button>
        </div>
      </aside>
      <main style={{ minWidth: 0 }}>
        <div style={{ position: 'sticky', top: 0, zIndex: 10, background: 'rgba(250,247,242,0.85)', backdropFilter: 'blur(10px)', borderBottom: '1px solid var(--line)', padding: '12px 28px', display: 'flex', alignItems: 'center', gap: 16, height: 56 }}>
          <div style={{ position: 'relative', width: 320 }}>
            <div style={{ position: 'absolute', left: 10, top: '50%', transform: 'translateY(-50%)', color: 'var(--ink-3)' }}>
              <I name="search" size={14} />
            </div>
            <input placeholder="ค้นหา users, orders, products..." style={{
              width: '100%', height: 32, padding: '0 12px 0 32px', borderRadius: 8,
              background: 'var(--bg-3)', border: '1px solid var(--line)', color: 'var(--ink)', fontSize: 13,
            }} />
          </div>
          <div style={{ flex: 1 }} />
          <Badge tone="primary" size="sm">Admin</Badge>
          <button style={{ background: 'transparent', border: 'none', padding: 6, cursor: 'pointer', color: 'var(--ink-2)' }}><I name="bell" size={16} /></button>
        </div>
        <div style={{ padding: '28px' }}>
          <div style={{ display: 'flex', alignItems: 'flex-end', justifyContent: 'space-between', gap: 16, marginBottom: 24 }}>
            <div>
              <h1 className="display" style={{ margin: 0, fontSize: 26, fontWeight: 600, letterSpacing: '-0.01em' }}>{title}</h1>
              {subtitle && <p style={{ margin: '4px 0 0', fontSize: 13.5, color: 'var(--ink-3)' }}>{subtitle}</p>}
            </div>
            {action}
          </div>
          {children}
        </div>
      </main>
    </div>
  );
}

function AdminKPI({ label, value, delta, prefix }) {
  const up = delta > 0;
  return (
    <div style={{ background: 'var(--bg-2)', border: '1px solid var(--line)', borderRadius: 10, padding: 18 }}>
      <div style={{ fontSize: 12, color: 'var(--ink-3)', textTransform: 'uppercase', letterSpacing: '0.05em', marginBottom: 10 }}>{label}</div>
      <div className="display" style={{ fontSize: 28, fontWeight: 600, letterSpacing: '-0.02em', fontVariantNumeric: 'tabular-nums' }}>
        {prefix}{value.toLocaleString()}
      </div>
      <div style={{ marginTop: 8, display: 'flex', alignItems: 'center', gap: 6, fontSize: 12.5 }}>
        <span style={{ display: 'inline-flex', alignItems: 'center', gap: 3, color: up ? 'var(--success)' : 'var(--danger)', fontWeight: 500 }}>
          <I name={up ? 'trendUp' : 'trendDown'} size={12} />
          {up ? '+' : ''}{delta}%
        </span>
        <span style={{ color: 'var(--ink-3)' }}>vs. เดือนก่อน</span>
      </div>
    </div>
  );
}

function RevenueChart({ data }) {
  const max = Math.max(...data);
  const min = Math.min(...data);
  const w = 720, h = 220, pad = 24;
  const xs = (i) => pad + (i / (data.length - 1)) * (w - pad * 2);
  const ys = (v) => h - pad - ((v - min) / (max - min)) * (h - pad * 2);
  const line = data.map((v, i) => `${i === 0 ? 'M' : 'L'} ${xs(i)} ${ys(v)}`).join(' ');
  const area = `${line} L ${xs(data.length - 1)} ${h - pad} L ${xs(0)} ${h - pad} Z`;
  return (
    <div style={{ background: 'var(--bg-2)', border: '1px solid var(--line)', borderRadius: 10, padding: 20 }}>
      <div style={{ display: 'flex', alignItems: 'flex-end', justifyContent: 'space-between', marginBottom: 14 }}>
        <div>
          <div style={{ fontSize: 13.5, fontWeight: 500 }}>รายได้ 30 วันย้อนหลัง</div>
          <div style={{ fontSize: 11.5, color: 'var(--ink-3)', marginTop: 2 }}>รวม ฿{data.reduce((a, b) => a + b, 0).toLocaleString()}</div>
        </div>
        <div style={{ display: 'flex', gap: 4 }}>
          {['7D', '30D', '90D'].map((p, i) => (
            <button key={p} style={{
              padding: '4px 10px', fontSize: 11.5, borderRadius: 6,
              background: i === 1 ? 'var(--bg-3)' : 'transparent',
              border: '1px solid ' + (i === 1 ? 'var(--line-2)' : 'transparent'),
              color: i === 1 ? 'var(--ink)' : 'var(--ink-3)', cursor: 'pointer',
            }}>{p}</button>
          ))}
        </div>
      </div>
      <svg viewBox={`0 0 ${w} ${h}`} style={{ width: '100%', height: 'auto' }}>
        <defs>
          <linearGradient id="rev" x1="0" y1="0" x2="0" y2="1">
            <stop offset="0%" stopColor="var(--primary)" stopOpacity="0.4"/>
            <stop offset="100%" stopColor="var(--primary)" stopOpacity="0"/>
          </linearGradient>
        </defs>
        {[0.25, 0.5, 0.75].map(t => (
          <line key={t} x1={pad} x2={w - pad} y1={pad + (h - pad * 2) * t} y2={pad + (h - pad * 2) * t} stroke="var(--line)" strokeDasharray="3 3"/>
        ))}
        <path d={area} fill="url(#rev)" />
        <path d={line} fill="none" stroke="var(--primary)" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" />
        {data.map((v, i) => (
          <circle key={i} cx={xs(i)} cy={ys(v)} r={i === data.length - 1 ? 4 : 0} fill="var(--primary)" />
        ))}
      </svg>
    </div>
  );
}

function AdminDashboard({ nav }) {
  return (
    <AdminLayout active="/admin" nav={nav}
      title="แดชบอร์ด"
      subtitle="ภาพรวม KindleStartup • 5 พ.ค. 2026"
      action={<div style={{ display: 'flex', gap: 8 }}>
        <Button variant="secondary" size="sm" icon="download">Export</Button>
        <Button variant="primary" size="sm" icon="plus">เพิ่มสินค้า</Button>
      </div>}
    >
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 12, marginBottom: 20 }}>
        <AdminKPI label="รายได้เดือนนี้" value={ADMIN_KPI.revenue.value} delta={ADMIN_KPI.revenue.delta} prefix="฿" />
        <AdminKPI label="ออเดอร์เดือนนี้" value={ADMIN_KPI.orders.value} delta={ADMIN_KPI.orders.delta} prefix="" />
        <AdminKPI label="ผู้ใช้ใหม่" value={ADMIN_KPI.newUsers.value} delta={ADMIN_KPI.newUsers.delta} prefix="" />
        <AdminKPI label="MRR" value={ADMIN_KPI.mrr.value} delta={ADMIN_KPI.mrr.delta} prefix="฿" />
      </div>

      <div style={{ display: 'grid', gridTemplateColumns: '2fr 1fr', gap: 16, marginBottom: 20 }}>
        <RevenueChart data={REVENUE_SERIES} />
        <div style={{ background: 'var(--bg-2)', border: '1px solid var(--line)', borderRadius: 10, padding: 20 }}>
          <div style={{ fontSize: 13.5, fontWeight: 500, marginBottom: 16 }}>ยอดขายตามระบบ</div>
          {[
            { sys: 'Academy', v: 198400, p: 0.82 },
            { sys: 'SEO',     v: 142800, p: 0.59 },
            { sys: 'Lumo',    v: 96400,  p: 0.40 },
            { sys: 'Bundle',  v: 49690,  p: 0.21 },
          ].map(r => (
            <div key={r.sys} style={{ marginBottom: 14 }}>
              <div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 12.5, marginBottom: 5 }}>
                <span style={{ display: 'inline-flex', alignItems: 'center', gap: 6 }}>
                  <SystemGlyph system={r.sys === 'Bundle' ? 'Academy' : r.sys} size={16} rounded={4} />
                  {r.sys}
                </span>
                <span style={{ color: 'var(--ink-2)', fontVariantNumeric: 'tabular-nums' }}>฿{r.v.toLocaleString()}</span>
              </div>
              <div style={{ height: 5, background: 'var(--bg-3)', borderRadius: 999 }}>
                <div style={{ width: (r.p * 100) + '%', height: '100%', background: 'var(--primary)', borderRadius: 999 }} />
              </div>
            </div>
          ))}
        </div>
      </div>

      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 16 }}>
        <AdminMiniTable
          title="10 ออเดอร์ล่าสุด"
          actionLabel="ดูทั้งหมด"
          onAction={() => nav('/admin/orders')}
          headers={['Order', 'ลูกค้า', 'จำนวน', '']}
          rows={ADMIN_ORDERS.slice(0, 10).map(o => [
            <span className="mono" style={{ fontSize: 11.5, color: 'var(--ink-3)' }}>{o.id}</span>,
            o.customer,
            <span style={{ fontVariantNumeric: 'tabular-nums' }}>฿{o.amount.toLocaleString()}</span>,
            <Badge tone={o.status === 'paid' ? 'success' : o.status === 'failed' ? 'danger' : o.status === 'refunded' ? 'warn' : 'neutral'} size="sm">
              {o.status}
            </Badge>,
          ])}
        />
        <AdminMiniTable
          title="10 ผู้ใช้ใหม่ล่าสุด"
          actionLabel="ดูทั้งหมด"
          onAction={() => nav('/admin/users')}
          headers={['ชื่อ', 'อีเมล', 'ออเดอร์', 'รวม']}
          rows={ADMIN_USERS.slice(0, 10).map(u => [
            <span style={{ display: 'inline-flex', alignItems: 'center', gap: 8 }}><Avatar name={u.name} size={22} /> {u.name}</span>,
            <span style={{ color: 'var(--ink-3)', fontSize: 12 }}>{u.email}</span>,
            u.orders,
            <span style={{ fontVariantNumeric: 'tabular-nums' }}>฿{u.spend.toLocaleString()}</span>,
          ])}
        />
      </div>
    </AdminLayout>
  );
}

function AdminMiniTable({ title, headers, rows, actionLabel, onAction }) {
  return (
    <div style={{ background: 'var(--bg-2)', border: '1px solid var(--line)', borderRadius: 10, overflow: 'hidden' }}>
      <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '14px 18px', borderBottom: '1px solid var(--line)' }}>
        <div style={{ fontSize: 13.5, fontWeight: 500 }}>{title}</div>
        {actionLabel && <button onClick={onAction} style={{ background: 'transparent', border: 'none', cursor: 'pointer', color: 'var(--ink-3)', fontSize: 12.5 }}>{actionLabel} →</button>}
      </div>
      <table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 13 }}>
        <thead>
          <tr>{headers.map(h => <th key={h} style={{ textAlign: 'left', padding: '8px 18px', fontSize: 11, fontWeight: 500, color: 'var(--ink-3)', textTransform: 'uppercase', letterSpacing: '0.05em', background: 'var(--bg-3)' }}>{h}</th>)}</tr>
        </thead>
        <tbody>
          {rows.map((r, i) => (
            <tr key={i} style={{ borderTop: '1px solid var(--line)' }}>
              {r.map((c, j) => <td key={j} style={{ padding: '10px 18px' }}>{c}</td>)}
            </tr>
          ))}
        </tbody>
      </table>
    </div>
  );
}

function AdminUsers({ nav }) {
  const [q, setQ] = useStateA('');
  const [filter, setFilter] = useStateA('all');
  const filtered = ADMIN_USERS.filter(u => {
    if (filter === 'active' && u.status !== 'active') return false;
    if (filter === 'inactive' && u.status === 'active') return false;
    if (q && !u.name.includes(q) && !u.email.includes(q)) return false;
    return true;
  });
  return (
    <AdminLayout active="/admin/users" nav={nav}
      title="ผู้ใช้"
      subtitle={`${ADMIN_USERS.length} ผู้ใช้ทั้งหมด`}
      action={<Button variant="primary" size="sm" icon="plus">เชิญผู้ใช้</Button>}
    >
      <div style={{ display: 'flex', gap: 8, marginBottom: 16, alignItems: 'center' }}>
        <div style={{ position: 'relative', flex: 1, maxWidth: 360 }}>
          <div style={{ position: 'absolute', left: 12, top: '50%', transform: 'translateY(-50%)', color: 'var(--ink-3)' }}>
            <I name="search" size={14} />
          </div>
          <input value={q} onChange={e => setQ(e.target.value)} placeholder="ค้นหาด้วยชื่อหรืออีเมล..." style={{
            width: '100%', height: 36, padding: '0 14px 0 36px', borderRadius: 8,
            background: 'var(--bg-2)', border: '1px solid var(--line)', color: 'var(--ink)', fontSize: 13,
          }} />
        </div>
        <div style={{ display: 'flex', gap: 4 }}>
          {[{ v: 'all', l: 'ทั้งหมด' }, { v: 'active', l: 'Active' }, { v: 'inactive', l: 'Inactive' }].map(f => (
            <button key={f.v} onClick={() => setFilter(f.v)} style={{
              padding: '7px 12px', borderRadius: 8, fontSize: 12.5,
              background: filter === f.v ? 'var(--bg-3)' : 'var(--bg-2)',
              border: '1px solid var(--line)', cursor: 'pointer',
              color: filter === f.v ? 'var(--ink)' : 'var(--ink-2)',
            }}>{f.l}</button>
          ))}
        </div>
      </div>

      <div style={{ background: 'var(--bg-2)', border: '1px solid var(--line)', borderRadius: 10, overflow: 'hidden' }}>
        <table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 13 }}>
          <thead>
            <tr style={{ background: 'var(--bg-3)' }}>
              {['ผู้ใช้', 'อีเมล', 'วันสมัคร', 'ออเดอร์', 'รวมใช้จ่าย', 'สถานะ', ''].map(h => (
                <th key={h} style={{ textAlign: 'left', padding: '10px 16px', fontSize: 11, fontWeight: 500, color: 'var(--ink-3)', textTransform: 'uppercase', letterSpacing: '0.05em' }}>{h}</th>
              ))}
            </tr>
          </thead>
          <tbody>
            {filtered.map(u => (
              <tr key={u.id} style={{ borderTop: '1px solid var(--line)', cursor: 'pointer' }}
                  onMouseEnter={e => e.currentTarget.style.background = 'var(--bg-3)'}
                  onMouseLeave={e => e.currentTarget.style.background = 'transparent'}>
                <td style={{ padding: '12px 16px' }}>
                  <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
                    <Avatar name={u.name} size={28} />
                    <span style={{ fontWeight: 500 }}>{u.name}</span>
                  </div>
                </td>
                <td style={{ padding: '12px 16px', color: 'var(--ink-2)' }}>{u.email}</td>
                <td style={{ padding: '12px 16px', color: 'var(--ink-2)' }}>{u.joined}</td>
                <td style={{ padding: '12px 16px', fontVariantNumeric: 'tabular-nums' }}>{u.orders}</td>
                <td style={{ padding: '12px 16px', fontVariantNumeric: 'tabular-nums' }}>฿{u.spend.toLocaleString()}</td>
                <td style={{ padding: '12px 16px' }}>
                  <Badge tone={u.status === 'active' ? 'success' : u.status === 'banned' ? 'danger' : 'neutral'} size="sm">
                    {u.status}
                  </Badge>
                </td>
                <td style={{ padding: '12px 16px', textAlign: 'right' }}>
                  <button style={{ background: 'transparent', border: 'none', cursor: 'pointer', color: 'var(--ink-3)', padding: 4 }}>
                    <I name="more" size={16} />
                  </button>
                </td>
              </tr>
            ))}
          </tbody>
        </table>
      </div>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginTop: 12, fontSize: 12.5, color: 'var(--ink-3)' }}>
        <span>แสดง 1–{filtered.length} จาก {ADMIN_USERS.length}</span>
        <div style={{ display: 'flex', gap: 4 }}>
          <button style={{ padding: '6px 10px', borderRadius: 6, background: 'var(--bg-2)', border: '1px solid var(--line)', color: 'var(--ink-3)', fontSize: 12, cursor: 'pointer' }}>ก่อนหน้า</button>
          <button style={{ padding: '6px 10px', borderRadius: 6, background: 'var(--bg-2)', border: '1px solid var(--line)', color: 'var(--ink)', fontSize: 12, cursor: 'pointer' }}>ถัดไป</button>
        </div>
      </div>
    </AdminLayout>
  );
}

function AdminOrders({ nav }) {
  const [filter, setFilter] = useStateA('all');
  const filtered = ADMIN_ORDERS.filter(o => filter === 'all' || o.status === filter);
  const counts = {
    all: ADMIN_ORDERS.length,
    paid: ADMIN_ORDERS.filter(o => o.status === 'paid').length,
    pending: ADMIN_ORDERS.filter(o => o.status === 'pending').length,
    failed: ADMIN_ORDERS.filter(o => o.status === 'failed').length,
    refunded: ADMIN_ORDERS.filter(o => o.status === 'refunded').length,
  };
  return (
    <AdminLayout active="/admin/orders" nav={nav}
      title="คำสั่งซื้อ"
      subtitle={`${ADMIN_ORDERS.length} คำสั่งซื้อทั้งหมด`}
      action={<div style={{ display: 'flex', gap: 8 }}>
        <Button variant="secondary" size="sm" icon="download">Export CSV</Button>
      </div>}
    >
      <div style={{ display: 'flex', gap: 4, marginBottom: 16, borderBottom: '1px solid var(--line)' }}>
        {[
          { v: 'all', l: 'ทั้งหมด' }, { v: 'paid', l: 'ชำระแล้ว' },
          { v: 'pending', l: 'รอชำระ' }, { v: 'failed', l: 'ล้มเหลว' },
          { v: 'refunded', l: 'คืนเงิน' },
        ].map(f => (
          <button key={f.v} onClick={() => setFilter(f.v)} style={{
            padding: '10px 14px', background: 'transparent', border: 'none',
            borderBottom: '2px solid ' + (filter === f.v ? 'var(--primary)' : 'transparent'),
            marginBottom: -1, cursor: 'pointer', fontSize: 13,
            color: filter === f.v ? 'var(--ink)' : 'var(--ink-3)',
            fontWeight: filter === f.v ? 500 : 400,
            display: 'inline-flex', alignItems: 'center', gap: 6,
          }}>
            {f.l}
            <span style={{ fontSize: 11, padding: '1px 6px', borderRadius: 999, background: 'var(--bg-3)', color: 'var(--ink-3)' }}>{counts[f.v]}</span>
          </button>
        ))}
      </div>
      <div style={{ background: 'var(--bg-2)', border: '1px solid var(--line)', borderRadius: 10, overflow: 'hidden' }}>
        <table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 13 }}>
          <thead>
            <tr style={{ background: 'var(--bg-3)' }}>
              {['Order ID', 'ลูกค้า', 'รายการ', 'จำนวน', 'วิธีชำระ', 'สถานะ', 'วันที่', ''].map(h => (
                <th key={h} style={{ textAlign: 'left', padding: '10px 16px', fontSize: 11, fontWeight: 500, color: 'var(--ink-3)', textTransform: 'uppercase', letterSpacing: '0.05em' }}>{h}</th>
              ))}
            </tr>
          </thead>
          <tbody>
            {filtered.map(o => (
              <tr key={o.id} style={{ borderTop: '1px solid var(--line)' }}
                  onMouseEnter={e => e.currentTarget.style.background = 'var(--bg-3)'}
                  onMouseLeave={e => e.currentTarget.style.background = 'transparent'}>
                <td style={{ padding: '12px 16px' }}>
                  <span className="mono" style={{ fontSize: 12, color: 'var(--ink)' }}>{o.id}</span>
                </td>
                <td style={{ padding: '12px 16px' }}>{o.customer}</td>
                <td style={{ padding: '12px 16px', color: 'var(--ink-2)', maxWidth: 240 }} className="truncate">{o.items}</td>
                <td style={{ padding: '12px 16px', fontWeight: 500, fontVariantNumeric: 'tabular-nums' }}>฿{o.amount.toLocaleString()}</td>
                <td style={{ padding: '12px 16px' }}>
                  <span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, color: 'var(--ink-2)', fontSize: 12.5 }}>
                    <I name={o.method === 'PromptPay' ? 'qr' : 'card'} size={12} /> {o.method}
                  </span>
                </td>
                <td style={{ padding: '12px 16px' }}>
                  <Badge tone={o.status === 'paid' ? 'success' : o.status === 'failed' ? 'danger' : o.status === 'refunded' ? 'warn' : 'neutral'} size="sm">{o.status}</Badge>
                </td>
                <td style={{ padding: '12px 16px', color: 'var(--ink-3)', fontSize: 12.5 }}>{o.date}</td>
                <td style={{ padding: '12px 16px', textAlign: 'right' }}>
                  <button style={{ background: 'transparent', border: 'none', cursor: 'pointer', color: 'var(--ink-3)' }}>
                    <I name="eye" size={14} />
                  </button>
                </td>
              </tr>
            ))}
          </tbody>
        </table>
      </div>
    </AdminLayout>
  );
}

Object.assign(window, { AdminLayout, AdminDashboard, AdminUsers, AdminOrders });
