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.registry')}

{t('hist.title')}{' '} {t('hist.title2')}

{t('hist.subtitle')}

{t('hist.total')}
{history.length}
{t('hist.accepted')}
{okCount}
{t('hist.failed')}
{errCount}
setQ(e.target.value)} placeholder={t('hist.search')} style={{paddingLeft:40}}/>
{t('hist.status')} {[{v:'all',l:t('hist.all')},{v:'ok',l:t('hist.accepted')},{v:'error',l:t('hist.failed')}].map(f=>)}
{t('hist.date')} {[{v:'7',l:t('hist.days7')},{v:'30',l:t('hist.days30')},{v:'90',l:t('hist.days90')},{v:'all',l:t('hist.everything')}].map(f=>)}
{sortedKeys.map(key =>
{fmtDay(key)}
{groups[key].length}
{groups[key].map((h,i)=>)}
)} {filtered.length===0 &&
{t('hist.no_results')}
}
{detail &&
setDetail(null)}>
e.stopPropagation()}>

{t('hist.details')}

{new Date(detail.when).toLocaleDateString('es',{weekday:'long',day:'2-digit',month:'long',year:'numeric'})} · {fmtTime(detail.when)}
{detail.status==='ok'?t('hist.plan_accepted'):t('hist.send_failed')}
{detail.status==='ok' &&
{detail.fpId}
}
{detail.status==='error' && detail.error &&
{detail.error}
}
{detail.from}
{AIRPORTS[detail.from]||''}
{detail.to}
{AIRPORTS[detail.to]||''}
{/* Identificacion */}
Identificacion
{detail.arcid &&
ARCID{detail.arcid}
}
Plan{detail.planName}
Reglas{RULES_FULL[detail.rules] || detail.rules}
{detail.flightType &&
Tipo vuelo{({S:'Regular',N:'No regular',G:'Aviacion general',M:'Militar',X:'Otros'})[detail.flightType] || detail.flightType}
} {detail.flightDate &&
Fecha{detail.flightDate}
} {/* Aeronave */}
Aeronave
Tipo{detail.aircraft}
{detail.wake &&
Estela{detail.wake}
} {detail.reg &&
REG{detail.reg}
} {detail.comEquipment &&
Equipo COM{detail.comEquipment}
} {detail.ssr &&
SSR{detail.ssr}
} {/* Ruta */}
Ruta
{detail.eobt &&
EOBT{detail.eobt}Z
} {detail.speed &&
Velocidad{detail.speed}
}
Nivel{detail.fl}
Ruta{detail.route}
EET{detail.dur}
{detail.altn &&
ALTN{detail.altn}
} {detail.altn2 &&
ALTN2{detail.altn2}
} {/* Suplementario */} {(detail.endurance || detail.pob || detail.pic || detail.colors || detail.emergencyRadio || detail.survivalEquipment || detail.lifeJackets) && <>
Suplementario
{detail.endurance &&
Autonomia{detail.endurance}
} {detail.pob &&
POB{detail.pob}
} {detail.pic &&
PIC{detail.pic}
} {detail.colors &&
Color/Marcas{detail.colors}
} {detail.emergencyRadio &&
Radio emergencia{detail.emergencyRadio}
} {detail.survivalEquipment &&
Equipo supervivencia{detail.survivalEquipment}
} {detail.lifeJackets &&
Chalecos{detail.lifeJackets}
} } {/* Observaciones */} {(detail.rmk || detail.opr) && <>
Observaciones
{detail.rmk &&
RMK{detail.rmk}
} {detail.opr &&
OPR{detail.opr}
} }
}
; }; window.History = History;