// 🚀 1. REAL MENU ACTION HANDLER async function menuAction(e, action, targetThreadId = null) { e.preventDefault(); e.stopPropagation(); // Close all menus instantly document.querySelectorAll('.action-menu').forEach(m => m.classList.add('hidden')); const activeId = ; const threadToActOn = targetThreadId || activeId; if (!threadToActOn && action !== 'safety_tips' && action !== 'delete_multiple') return; // A. SAFETY TIPS (UI Action) if (action === 'safety_tips') { alert("Safety Tip: Never share OTPs, passwords, or pay in advance without verifying the product!"); return; } // B. DELETE CHAT (Database Action) if (action === 'delete_chat') { if (!confirm("Are you sure you want to delete this chat permanently?")) return; const fd = new FormData(); fd.append('action', 'delete_chat'); fd.append('thread_id', threadToActOn); await fetch('ajax_actions.php', { method: 'POST', body: fd }); // If they deleted the chat they are currently looking at, send them to the empty inbox if (threadToActOn === activeId) { window.location.href = 'chats.php'; } else { window.location.reload(); // Refresh to update left list } } // C. BLOCK USER (Database Action) if (action === 'block_user') { if (!confirm("Block this user? You will no longer receive messages from them.")) return; const fd = new FormData(); fd.append('action', 'block_user'); fd.append('thread_id', threadToActOn); await fetch('ajax_actions.php', { method: 'POST', body: fd }); window.location.href = 'chats.php'; } // D. MARK IMPORTANT if (action === 'mark_important') { // UI trick: Add a star icon instantly to make it feel fast e.target.innerText = "⭐ Unmark important"; const fd = new FormData(); fd.append('action', 'mark_important'); fd.append('thread_id', threadToActOn); fetch('ajax_actions.php', { method: 'POST', body: fd }); } } // 🚀 2. REAL REPORT USER HANDLER async function submitReport() { const selected = document.querySelector('input[name="report_reason"]:checked'); if (!selected) { alert('Please select a reason for reporting.'); return; } const activeId = ; if (!activeId) return; // Change button text to show it's loading const btn = event.target; const originalText = btn.innerText; btn.innerText = "Submitting..."; btn.disabled = true; const fd = new FormData(); fd.append('action', 'report_user'); fd.append('thread_id', activeId); fd.append('reason', selected.value); try { const response = await fetch('ajax_actions.php', { method: 'POST', body: fd }); const result = await response.json(); if(result.status === 'success') { closeReportModal(); // Show a nice success message setTimeout(() => alert("Thank you. Our Trust & Safety team will review this report."), 350); } } catch (e) { alert("Network error. Please try again."); } finally { btn.innerText = originalText; btn.disabled = false; } }