const t = window.t || (k => k); const History = () => { const {history, plans, go, toast} = useApp(); const [filter, setFilter] = useState('all'); const [range, setRange] = useState('30'); const [q, setQ] = useState(''); const [detail, setDetail] = useState(null); const now = Date.now(); const filtered = history.filter(h => { if (filter!=='all' && h.status!==filter) return false; if (range!=='all') { const t=new Date(h.when).getTime(); if (now-t > parseInt(range)*86400000) return false; } if (q) { const s=q.toLowerCase(); if (!h.planName.toLowerCase().includes(s) && !h.from.toLowerCase().includes(s) && !h.to.toLowerCase().includes(s) && !(h.fpId||'').toLowerCase().includes(s)) return false; } return true; }); const groups = {}; filtered.forEach(h => { const key=h.when.slice(0,10); if (!groups[key]) groups[key]=[]; groups[key].push(h); }); const sortedKeys = Object.keys(groups).sort((a,b)=>b.localeCompare(a)); const fmtDay = (iso) => { const d=new Date(iso); const today=new Date();today.setHours(0,0,0,0); const diff=Math.floor((today-d)/86400000); if (diff===0) return t('hist.today'); if (diff===1) return t('hist.yesterday'); if (diff<7) return d.toLocaleDateString('es',{weekday:'long'}).replace(/^./,c=>c.toUpperCase()); return d.toLocaleDateString('es',{weekday:'short',day:'2-digit',month:'short'}).replace(/^./,c=>c.toUpperCase()); }; const fmtTime = (iso) => new Date(iso).toLocaleTimeString('es',{hour:'2-digit',minute:'2-digit'}); const okCount = history.filter(h=>h.status==='ok').length; const errCount = history.filter(h=>h.status==='error').length; return
{t('hist.subtitle')}