import { useState } from 'react'; const BACKEND_URL = import.meta.env.VITE_BACKEND_URL || (import.meta.env.DEV ? 'http://localhost:8000' : ''); const STATUS_CONFIG = { STANDBY: { label: 'STANDBY', bg: '#f1f3f4', color: '#5f6368' }, READY: { label: 'READY', bg: 'rgba(52,168,83,0.1)', color: '#1e8e3e' }, URGENT: { label: 'URGENT', bg: 'rgba(234,67,53,0.1)', color: '#d93025' }, SIGNAL: { label: 'SIGNAL', bg: 'rgba(251,188,4,0.1)', color: '#e37400' }, }; function formatDate(dateStr) { if (!dateStr) return ''; const d = new Date(dateStr); return d.toLocaleDateString('fr-FR', { day: 'numeric', month: 'short' }); } function formatTime(timeStr) { if (!timeStr) return ''; const d = new Date(timeStr); return d.toLocaleString('fr-FR', { day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' }); } export default function ProjectCard({ project, status, alerts }) { const st = STATUS_CONFIG[status] || STATUS_CONFIG.STANDBY; const [expanded, setExpanded] = useState(false); const [sources, setSources] = useState(null); const [loading, setLoading] = useState(false); const handleClick = async () => { if (expanded) { setExpanded(false); return; } if (!sources) { setLoading(true); try { const res = await fetch(`${BACKEND_URL}/api/project/${project.id}/sources`); setSources(await res.json()); } catch (err) { console.error(err); } finally { setLoading(false); } } setExpanded(true); }; return (
e.currentTarget.style.boxShadow = '0 2px 8px rgba(0,0,0,0.08)'} onMouseLeave={(e) => e.currentTarget.style.boxShadow = 'none'} >
PROJET {st.label}

{project.name}

{project.contact && (

{project.contact}

)} {alerts && alerts.length > 0 && ( )} {!expanded && (
Cliquer pour voir les sources
)} {loading && (
Chargement...
)} {expanded && sources && (
e.stopPropagation()} style={{ marginTop: '14px', borderTop: '1px solid #e0e0e0', paddingTop: '14px', animation: 'fadeIn 0.3s ease-out', }}> {/* Emails */} {sources.emails && sources.emails.length > 0 && (
EMAILS
{sources.emails.map((email, i) => (
{email.subject} = 5 ? '#d93025' : '#5f6368', fontWeight: email.days_since_reply >= 5 ? 600 : 400, }}> {email.days_since_reply != null ? `${email.days_since_reply}j` : ''}
De : {email.from} · {formatDate(email.date)}
{email.body}
Repondre Ouvrir dans Gmail
))}
)} {/* Events */} {sources.events && sources.events.length > 0 && (
CALENDRIER
{sources.events.map((event, i) => (
{event.title}
{formatTime(event.time)} {event.prep_block ? Prep OK : Pas de prep }
Ouvrir l'agenda
))}
)} {/* Web signal */} {sources.search && (
SIGNAL EXTERNE
{sources.search}
)}
Cliquer pour fermer
)}
); }