import { useIdentity, useCollection, useNotify } from '@deplixo/sdk'; import { HeartIcon, LogoutIcon } from './components/Icons.jsx'; import Welcome from './components/Welcome.jsx'; import Chat from './components/Chat.jsx'; import Admin from './components/Admin.jsx'; function App() { const { user } = useIdentity(); const [view, setView] = useState('welcome'); // welcome | chat | admin const [userName, setUserName] = useState(''); const [conversationId, setConversationId] = useState(null); const [toast, setToast] = useState(null); const { items: friends, add: addFriend, update: updateFriend } = useCollection('friends'); const { add: addShare } = useCollection('shares'); const notify = useNotify(); const handleStart = async (name) => { setUserName(name); setConversationId(`conv-${Date.now()}`); // Register or update friend record const existing = (friends || []).find(f => f.author?.id === user?.id); try { if (existing) { await updateFriend(existing.id, { name, lastSeen: Date.now(), conversations: (existing.value?.conversations || 0) + 1, }); } else { await addFriend({ name, lastSeen: Date.now(), conversations: 1, }); } } catch (err) { console.warn('friend registration failed', err); } setView('chat'); }; const handleShare = async (payload) => { if (!payload.consent) { setToast('Sua conversa permanece privada. đź’›'); setTimeout(() => setToast(null), 3000); return; } try { await addShare({ mood: payload.mood, summary: payload.summary, messages: payload.messages, userName, }); try { await notify({ title: 'Novo compartilhamento', body: `${userName} compartilhou um resumo da conversa.`, }); } catch {} setToast('Obrigado por compartilhar! đź’›'); setTimeout(() => setToast(null), 3000); } catch (err) { console.error('share failed', err); setToast('NĂŁo foi possĂvel compartilhar agora.'); setTimeout(() => setToast(null), 3000); } }; const goHome = () => { setView('welcome'); }; return (