/* global React, Card, StatusBadge, StatusGlyph, STATUS_META, Ic, Button, Input, Breadcrumb, TrendChart, VS, LoadingState, ErrorState, statusFromAlarm */ function SessionDetailScreen({ machineId, machineName, sessionDate, onBack }) { const [detail, setDetail] = React.useState(null); const [err, setErr] = React.useState(''); const [activePoint, setActivePoint] = React.useState(null); const [trend, setTrend] = React.useState(null); const [trendBusy, setTrendBusy] = React.useState(false); const [notes, setNotes] = React.useState({}); const [notesBusy, setNotesBusy] = React.useState(false); const [notesMsg, setNotesMsg] = React.useState(''); React.useEffect(() => { (async () => { try { const d = await VS.sessionDetail(machineId, sessionDate); setDetail(d); setNotes(d.notes || {}); if (d.points && d.points.length > 0) { const first = d.points[0]; setActivePoint(first); loadTrend(first.point_name); } } catch (e) { setErr(e.message); } })(); }, [machineId, sessionDate]); async function loadTrend(pointName) { setTrend(null); setTrendBusy(true); try { const t = await VS.trend(machineId, pointName, 50); setTrend(t); } catch (e) { /* ignore — point może nie mieć historii */ } finally { setTrendBusy(false); } } async function saveNotes() { setNotesBusy(true); setNotesMsg(''); try { await VS.saveNotes(machineId, sessionDate, notes); setNotesMsg('Zapisano.'); setTimeout(() => setNotesMsg(''), 2500); } catch (e) { setNotesMsg('Błąd: ' + e.message); } finally { setNotesBusy(false); } } if (err) return ; if (!detail) return ; const points = detail.points || []; const worst = points.reduce((a, p) => Math.max(a, p.alarm_level || 0), 0); const sessionStatus = statusFromAlarm(worst); const dateStr = sessionDate ? `${sessionDate.slice(0,4)}-${sessionDate.slice(4,6)}-${sessionDate.slice(6,8)}` : ''; const alarmPoint = points.find(p => (p.alarm_level || 0) >= 3); const thresholds = (activePoint && activePoint.unit === 'mm/s') ? { warn: 4.5, alarm: 7.1 } : (activePoint && activePoint.unit === 'g') ? { warn: 2.0, alarm: 3.5 } : { warn: null, alarm: null }; return (

Sesja {dateStr}

Maszyna  {detail.machine_name} Punkty  {points.length} Norma  ISO 10816-3
{alarmPoint && (
Alarm: {alarmPoint.point_name} · {alarmPoint.overall_value?.toFixed(2)} {alarmPoint.unit}
)}
{/* Trend */}
Trend · {activePoint ? activePoint.point_name : 'wybierz punkt'}
{trend ? `${trend.data.length} pomiarów · ` : ''} {activePoint?.unit || ''}
{trendBusy &&
Ładowanie trendu…
} {!trendBusy && trend && trend.data.length > 0 && ( ({ date: d.date, value: d.value }))} thresholds={thresholds} unit={trend.unit || activePoint?.unit || ''} /> )} {!trendBusy && (!trend || trend.data.length === 0) && (
Brak historii dla tego punktu.
)}
{/* Punkty */}

Punkty pomiarowe

{points.length} punktów
kliknij wiersz aby zobaczyć trend
Status
Czas
Łożysko
Punkt
Wartość
Jednostka
{points.length === 0 && (
Brak punktów w tej sesji.
)} {points.map((p, i) => { const st = statusFromAlarm(p.alarm_level); const active = activePoint && activePoint.point_name === p.point_name; return (
{ setActivePoint(p); loadTrend(p.point_name); }} style={{ display: 'grid', gridTemplateColumns: '60px 80px 80px 1fr 120px 80px', padding: '10px 16px', borderBottom: i < points.length - 1 ? '1px solid var(--hairline)' : 'none', alignItems: 'center', fontSize: 12.5, cursor: 'pointer', background: active ? 'var(--bg-sunken)' : 'transparent', }} onMouseEnter={(e) => { if (!active) e.currentTarget.style.background = 'var(--bg-sunken)'; }} onMouseLeave={(e) => { if (!active) e.currentTarget.style.background = 'transparent'; }} > {p.time || '—'} {p.bearing_number ? `Ł${p.bearing_number}` : '—'} {p.point_name} {p.overall_value != null ? p.overall_value.toFixed(3) : '—'} {p.unit || ''}
); })}
{/* Notatki */}
Notatki diagnostyka
{notesMsg && {notesMsg}}
setNotes({ ...notes, uwagi: v })} /> setNotes({ ...notes, ocena: v })} /> setNotes({ ...notes, zalecenia: v })} /> setNotes({ ...notes, cel_pomiaru: v })} single /> setNotes({ ...notes, operator: v })} single /> setNotes({ ...notes, zatwierdzil: v })} single />
); } function NoteField({ label, value, onChange, single }) { return (