// ─────────────────────────────────────────────────────────── // Huio Control Panel — Push Broadcast View (cp-broadcast-view.jsx) // ─────────────────────────────────────────────────────────── if (!window.CP_STYLES) throw new Error('[cp-broadcast-view] window.CP_STYLES not loaded'); function renderBroadcast({ lang, t, appStyles: rawAppStyles, users = [], logs = [], broadcastTarget, setBroadcastTarget, broadcastUserId, setBroadcastUserId, broadcastTitle, setBroadcastTitle, broadcastBody, setBroadcastBody, isBroadcasting, handleSendBroadcast, }) { const appStyles = rawAppStyles || window.CP_STYLES || {}; const formatPhone = window.formatPhone || ((p) => p || '—'); const userList = Array.isArray(users) ? users : []; const logList = Array.isArray(logs) ? logs : []; const totalUsersCount = userList.length; // Single-pass telemetry & cohort aggregation (Zero intermediate array allocations) let usersWithPushTokenCount = 0; let targetCohort = []; let targetCohortWithPush = 0; for (let i = 0; i < totalUsersCount; i++) { const u = userList[i]; if (!u) continue; if (u.pushToken) { usersWithPushTokenCount++; } let isTarget = false; if (broadcastTarget === 'all') { isTarget = true; } else if (broadcastTarget === 'organizers') { isTarget = (u.role === 'organizer' || u.role === 'both'); } else if (broadcastTarget === 'participants') { isTarget = (u.role === 'participant' || u.role === 'both'); } else if (broadcastTarget === 'user') { isTarget = (u.id === broadcastUserId); } if (isTarget) { targetCohort.push(u); if (u.pushToken) { targetCohortWithPush++; } } } const pushReachPercentage = totalUsersCount > 0 ? Math.round((usersWithPushTokenCount / totalUsersCount) * 100) : 0; // Bounded log scanning for recent broadcast activities (O(1) memory bound on React DOM) const broadcastLogs = []; for (let i = logList.length - 1; i >= 0 && broadcastLogs.length < 50; i--) { const l = logList[i]; const txt = typeof l?.text === 'string' ? l.text : ''; if (txt && (txt.includes('Broadcasted') || txt.includes('Đã phát') || txt.includes('[DEMO]'))) { broadcastLogs.push(l); } } return (

{t('broadcast.title')}

{t('broadcast.sub')}

{broadcastTarget === 'user' && (
)}
setBroadcastTitle(e.target.value)} placeholder={lang === 'vi' ? 'Tiêu đề thông báo' : 'Enter notification title'} className="hu-input" style={{ width: '100%', minHeight: '38px', fontSize: '13px' }} required />