/* ============================================================ js/pesan.js โ Media komunikasi pengurus v2.2 ============================================================ */ window.labelJenisPesan = { permintaan_bantuan: 'Permintaan Bantuan', koordinasi: 'Koordinasi', pengumuman: 'Pengumuman' }; var _jenisEmoji = { permintaan_bantuan: '๐', koordinasi: '๐', pengumuman: '๐ข' }; /* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Floating detail box โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */ window.openPesanDetail = async function (p) { var fl = document.getElementById('pesan-detail-float'); if (!fl) return; var jenis = p.jenis || 'koordinasi'; var emoji = _jenisEmoji[jenis] || '๐ฌ'; var jenisLabel = window.labelJenisPesan[jenis] || jenis; var isBroadcast = !p.penerima_id; var roleLabel = p.role_pengirim === 'pimpinan_daerah' ? ' Pimpinan Daerah' : ' Pengurus Masjid'; /* Accent bar */ document.getElementById('pdf-accent-bar').className = 'pdf-accent-bar ' + jenis; /* Icon */ var icon = document.getElementById('pdf-icon'); icon.textContent = emoji; icon.className = 'pdf-icon ' + jenis; /* Title (judul pesan) + subtitle (jenis) */ document.getElementById('pdf-title').textContent = p.judul || 'Pesan'; document.getElementById('pdf-subtitle').textContent = jenisLabel; /* Isi */ document.getElementById('pdf-isi').textContent = p.isi || '(tidak ada isi)'; /* Info rows */ document.getElementById('pdf-pengirim').textContent = p.nama_pengirim || '-'; document.getElementById('pdf-role').innerHTML = roleLabel; document.getElementById('pdf-jenis-label').textContent = emoji + ' ' + jenisLabel; document.getElementById('pdf-waktu').textContent = p.created_fmt || '-'; /* Broadcast badge */ document.getElementById('pdf-row-broadcast').style.display = isBroadcast ? '' : 'none'; /* Baru badge */ document.getElementById('pdf-row-baru').style.display = (p.status === 'baru') ? '' : 'none'; /* Close */ document.getElementById('pdf-close').onclick = window.closePesanDetail; /* Show */ fl.style.display = 'flex'; /* Mark as read if it is new and we are not the sender */ if (p.status === 'baru' && p.pengirim_id != window.appAuth.id) { try { var formData = new FormData(); formData.append('id', p.id); formData.append('status', 'dibaca'); await fetch('php/update_pesan_status.php', { method: 'POST', body: formData }); p.status = 'dibaca'; // Remove 'baru' indicator from card visually var cardEl = document.querySelector('.p-card[data-id="' + p.id + '"]'); if (cardEl) { cardEl.classList.remove('baru'); var dot = cardEl.querySelector('.p-new'); if (dot) dot.remove(); } // Immediately update the notification badge if (window.pollPesanNotification) window.pollPesanNotification(); } catch (e) { console.error('Failed to update message status', e); } } }; window.closePesanDetail = function () { var fl = document.getElementById('pesan-detail-float'); if (fl) fl.style.display = 'none'; }; /* โโ Panel open/close โโ */ window.openPesanPanel = async function () { var panel = document.getElementById('panel-pesan'); if (panel) { var sidebar = document.getElementById('sidebar'); if (sidebar) sidebar.style.display = 'none'; var lap = document.getElementById('panel-laporan'); if (lap) lap.style.display = 'none'; panel.style.display = 'flex'; await window.loadPesan(); } }; window.closePesanPanel = function () { var p = document.getElementById('panel-pesan'); if (p) p.style.display = 'none'; window.closePesanDetail(); // Auto-open sidebar var sidebar = document.getElementById('sidebar'); if (sidebar) sidebar.style.display = 'flex'; }; /* โโ Load & render pesan โโ */ window.loadPesan = async function () { var container = document.getElementById('pesan-list-container'); if (!container) return; container.innerHTML = '