document.addEventListener('click', e => { if (!e.target.closest('.emoji-picker') && !e.target.closest('.input-btn')) document.getElementById('emojiPicker')?.classList.remove('show'); }); // PWA prompts (function() { const getCookie = n => { const m = document.cookie.match(new RegExp('(^| )' + n + '=([^;]+)')); return m ? m[2] : null; }; const setCookie = (n, v, d) => { const dt = new Date(); dt.setTime(dt.getTime() + (d*24*60*60*1000)); document.cookie = n + '=' + v + ';expires=' + dt.toUTCString() + ';path=/;SameSite=Lax'; }; const isStandalone = () => window.matchMedia('(display-mode: standalone)').matches || window.navigator.standalone === true; const shouldShowPwa = () => { if (isStandalone()) return false; if (getCookie('pwa_chat_never') === '1') return false; const later = getCookie('pwa_chat_later'); if (later && Date.now() < parseInt(later)) return false; if (getCookie('pwa_chat_done') === '1') return false; return true; }; const shouldShowPush = () => { if (!('Notification' in window)) return false; if (Notification.permission !== 'default') return false; if (getCookie('push_chat_never') === '1') return false; const later = getCookie('push_chat_later'); if (later && Date.now() < parseInt(later)) return false; return true; }; window.showPwaTab = tab => { document.querySelectorAll('.pwa-tab').forEach(t => t.classList.remove('active')); document.querySelectorAll('.pwa-steps').forEach(s => s.classList.remove('active')); event.target.classList.add('active'); document.getElementById('pwa-' + tab)?.classList.add('active'); }; window.closePwaPrompt = action => { document.getElementById('pwaPrompt')?.classList.remove('show'); if (action === 'never') setCookie('pwa_chat_never', '1', 1825); else if (action === 'later') setCookie('pwa_chat_later', Date.now() + 604800000, 30); else if (action === 'done') setCookie('pwa_chat_done', '1', 365); setTimeout(maybeShowPush, 1000); }; window.closePushPrompt = action => { document.getElementById('pushPrompt')?.classList.remove('show'); if (action === 'never') setCookie('push_chat_never', '1', 1825); else if (action === 'later') setCookie('push_chat_later', Date.now() + 259200000, 30); }; window.enablePushFromPrompt = async () => { document.getElementById('pushPrompt')?.classList.remove('show'); if (typeof toggleNotifications === 'function') await toggleNotifications(); }; const maybeShowPush = () => { if (shouldShowPush()) setTimeout(() => document.getElementById('pushPrompt')?.classList.add('show'), 2000); }; if (shouldShowPwa()) setTimeout(() => document.getElementById('pwaPrompt')?.classList.add('show'), 3000); else setTimeout(maybeShowPush, 5000); })(); // Video/Audio Calls function startAudioCall() { if (!currentChat) return; const chatName = currentChat.name || 'Chat'; const callWindow = window.open('', '_blank', 'width=400,height=500'); callWindow.document.write(` Audio Call - ${escapeHtml(chatName)}
${currentChat.avatar || '👤'}
${escapeHtml(chatName)}
🔊 Audio Call Connected

Note: This is a placeholder for future WebRTC integration

`); } function startVideoCall() { if (!currentChat) return; const chatName = currentChat.name || 'Chat'; const callWindow = window.open('', '_blank', 'width=800,height=600'); callWindow.document.write(` Video Call - ${escapeHtml(chatName)}
👤
You
${currentChat.avatar || '👤'}
${escapeHtml(chatName)}
`); } init();