/** * PWA Install Prompt — shows install button when PWA is installable (Task 5.24). */ import React, { useState, useEffect, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { Download, X } from 'lucide-react'; interface BeforeInstallPromptEvent extends Event { prompt: () => Promise; userChoice: Promise<{ outcome: 'accepted' | 'dismissed' }>; } const DISMISS_KEY = 'leocrm_pwa_install_dismissed'; export function PWAInstallPrompt() { const { t } = useTranslation(); const [deferredPrompt, setDeferredPrompt] = useState(null); const [visible, setVisible] = useState(false); useEffect(() => { const dismissed = localStorage.getItem(DISMISS_KEY); if (dismissed) return; const handler = (e: Event) => { e.preventDefault(); setDeferredPrompt(e as BeforeInstallPromptEvent); setVisible(true); }; window.addEventListener('beforeinstallprompt', handler); return () => window.removeEventListener('beforeinstallprompt', handler); }, []); const handleInstall = useCallback(async () => { if (!deferredPrompt) return; await deferredPrompt.prompt(); const choice = await deferredPrompt.userChoice; if (choice.outcome === 'accepted') { setVisible(false); } setDeferredPrompt(null); }, [deferredPrompt]); const handleDismiss = useCallback(() => { localStorage.setItem(DISMISS_KEY, '1'); setVisible(false); }, []); if (!visible || !deferredPrompt) return null; return (

{t('pwa.installTitle')}

{t('pwa.installDescription')}

); }