// ─────────────────────────────────────────────────────────── // Huio Control Panel — Live Support View (cp-support-view.jsx) // ─────────────────────────────────────────────────────────── if (!window.CP_STYLES) throw new Error('[cp-support-view] window.CP_STYLES not loaded'); function renderSupport({ lang, t, appStyles: rawAppStyles, supportQueue = [], supportLoading, supportFilter, setSupportFilter, supportSearchQuery, setSupportSearchQuery, selectedSupportConv, setSelectedSupportConv, fetchSupportQueue, supabaseClient, }) { const appStyles = rawAppStyles || window.CP_STYLES || {}; // Safe data array & pre-normalized filter criteria (O(1) loop invariant hoisting) const queueList = Array.isArray(supportQueue) ? supportQueue : []; const q = (typeof supportSearchQuery === 'string') ? supportSearchQuery.trim().toLowerCase() : ''; const totalCount = queueList.length; // Single-pass computation of metrics (0 intermediate array allocations) let waitingCount = 0; for (let i = 0; i < totalCount; i++) { if (queueList[i]?.is_waiting_reply) waitingCount++; } // Filters with defensive null/type safety on string properties const filteredQueue = queueList.filter(conv => { if (!conv) return false; if (!q) return true; const name = (conv.user_name || '').toLowerCase(); const phone = String(conv.user_phone || ''); const msg = (conv.last_message_text || '').toLowerCase(); return name.includes(q) || phone.includes(q) || msg.includes(q); }); return (
{t('support.sub') || 'Manage all live support conversations with users.'}
| {t('support.col.user') || 'User'} | {t('support.col.last_message') || 'Last message'} | {t('support.col.time') || 'Time'} | {t('support.col.status') || 'Status'} | {lang === 'vi' ? 'Hành động' : 'Actions'} |
|---|---|---|---|---|
|
⏳
{lang === 'vi' ? 'Đang tải hàng đợi hỗ trợ...' : 'Loading support queue...'}
|
||||
|
🎉
{supportFilter === 'waiting'
? (lang === 'vi' ? 'Không có yêu cầu nào đang chờ phản hồi!' : 'All support requests have been answered!')
: (t('support.empty') || 'No support conversations found')}
{lang === 'vi' ? 'Hệ thống hỗ trợ đang hoạt động bình thường.' : 'All incoming messages are handled.'}
|
||||
|
{conv.user_avatar ? (
{displayName}
{unreadNum > 0 && (
{unreadNum}
)}
{conv.user_phone ? conv.user_phone : 'No phone'}
|
{conv.last_message_text || (
{lang === 'vi' ? 'Chưa có tin nhắn' : 'No messages'}
)}
|
{timeStr}
{dateStr}
|
{conv.is_waiting_reply ? ( 🔴 {t('support.status.waiting') || 'Waiting'} ) : ( ✓ {t('support.status.replied') || 'Replied'} )} | |