// ─────────────────────────────────────────────────────────── // Huio Control Panel — Waitlist Queue View (cp-waitlist-view.jsx) // ─────────────────────────────────────────────────────────── if (!window.CP_STYLES) throw new Error('[cp-waitlist-view] window.CP_STYLES not loaded'); // Senior High-Load Optimization: Static style hoisting to eliminate heap allocations during list rendering const STATIC_WRAPPER_CARD_STYLE = { padding: 0, overflow: 'hidden' }; const STATIC_EMPTY_BOX_STYLE = { padding: '40px', textAlign: 'center', color: 'var(--hu-fg-3)' }; const STATIC_ROW_STYLE = { borderBottom: '1px solid var(--hu-border-light)' }; const STATIC_BADGE_BASE = { display: 'inline-block', padding: '2px 8px', borderRadius: '4px', fontSize: '11px', fontWeight: 'bold', }; // O(1) status badge theme lookup const BADGE_STATUS_THEMES = { invited: { backgroundColor: '#fff3f0', color: '#cc2200' }, accepted: { backgroundColor: '#d4f0d4', color: '#1a6a1a' }, default: { backgroundColor: '#e0e0e0', color: '#555555' }, }; // Safe date formatters preventing runtime crashes on invalid/missing ISO strings function formatRequestedDate(val, locale) { if (!val) return '—'; try { const d = new Date(val); return isNaN(d.getTime()) ? '—' : d.toLocaleDateString(locale); } catch { return '—'; } } function formatExpiresDateTime(val, locale) { if (!val) return '—'; try { const d = new Date(val); return isNaN(d.getTime()) ? '—' : d.toLocaleString(locale); } catch { return '—'; } } function renderWaitlist({ lang = 'vi', t: rawT, appStyles: rawAppStyles, waitlistEntries: rawWaitlistEntries = [], }) { // Defensive fallbacks for shell utilities and data structures const appStyles = rawAppStyles || window.CP_STYLES || {}; const t = typeof rawT === 'function' ? rawT : (k) => k; const waitlistEntries = Array.isArray(rawWaitlistEntries) ? rawWaitlistEntries : []; const isEn = lang === 'en'; const locale = isEn ? 'en-GB' : 'vi-VN'; return (

{t('nav.waitlist')}

{isEn ? 'Manage waitlist registrations, active invitations, and queue order across all groups.' : 'Quản lý danh sách đăng ký chờ, lời mời đang hoạt động và thứ tự hàng đợi trên toàn bộ các nhóm.'}

{waitlistEntries.length === 0 ? (
{isEn ? 'No waitlist entries found.' : 'Không tìm thấy lượt đăng ký hàng chờ nào.'}
) : ( {waitlistEntries.map((entry, idx) => { if (!entry) return null; const entryIdStr = entry.id != null ? String(entry.id) : `waitlist_${idx}`; const rawStatus = typeof entry.status === 'string' ? entry.status : ''; const normalizedStatus = rawStatus.toLowerCase(); const theme = BADGE_STATUS_THEMES[normalizedStatus] || BADGE_STATUS_THEMES.default; const isInvited = normalizedStatus === 'invited'; const badgeStyle = { ...STATIC_BADGE_BASE, backgroundColor: theme.backgroundColor, color: theme.color, }; return ( ); })}
{isEn ? 'Group' : 'Dây hụi'} {isEn ? 'Candidate' : 'Ứng viên'} {isEn ? 'Phone' : 'Số điện thoại'} {isEn ? 'Requested At' : 'Ngày đăng ký'} {isEn ? 'Status' : 'Trạng thái'} {isEn ? 'Expires At' : 'Hết hạn'}
{entry.hui_groups?.name || (isEn ? 'Unknown Group' : 'Dây hụi không rõ')} {entry.profiles?.name || (isEn ? 'Unknown' : 'Ẩn danh')} {entry.profiles?.phone || '—'} {formatRequestedDate(entry.requested_at, locale)} {(rawStatus || 'UNKNOWN').toUpperCase()} {isInvited && entry.expires_at ? formatExpiresDateTime(entry.expires_at, locale) : '—'}
)}
); } window.CpWaitlistView = { renderWaitlist, };