import { useTranslation } from 'react-i18next' import { Info } from 'lucide-react' import { Alert, AlertDescription, AlertTitle } from '@workspace/ui/components/alert' import { Badge } from '@workspace/ui/components/badge' import { Button } from '@workspace/ui/components/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@workspace/ui/components/card' import type { Prediction, TimelinePoint } from '@/lib/api' import { downloadPrediction, formatDelta, formatScore, formatSeconds, nearestWindow, scoreDomain } from '@/lib/timeline' interface Props { result: Prediction | null currentTime: number selectedIndex: number | null onSelect: (point: TimelinePoint) => void } export function TimelinePanel({ result, currentTime, selectedIndex, onSelect }: Props) { const { t } = useTranslation() const points = result?.timeline?.points ?? [] const selected = points.find(point => point.index === selectedIndex) ?? null const active = nearestWindow(points, currentTime) const [low, high] = scoreDomain(points) const duration = Math.max(1, result?.duration_seconds ?? 1, ...points.map(point => point.end_seconds)) const x = (time: number) => 72 + time / duration * 876 const y = (score: number) => 260 - (score - low) / (high - low) * 220 const curves = [ { key: 'valence' as const, label: t('window.valenceCurve'), color: 'var(--chart-valence)' }, { key: 'arousal' as const, label: t('window.arousalCurve'), color: 'var(--chart-arousal)' } ] return (
{t('window.sectionNumber')}
{t('window.title')}
{t('window.badge')}
{t('window.desc')}
{t('window.alertTitle')} {t('window.alertDesc')} {result?.timeline &&

{t('window.methodNote')}

}
{!points.length ? (
{result ? result.timeline ? t('window.emptyNoData') : t('window.emptyOldResult') : t('window.emptyWaiting')}
) : ( <>
{curves.map(curve => ( {curve.label} ))}
{t('window.playbackPos', { time: formatSeconds(currentTime) })}
{points.length === 1 && (

{t('window.singleWindowNote')}

)}
{[0, 1, 2, 3, 4].map(tick => { const score = low + (high - low) * tick / 4 return ( {score.toFixed(2)} {(duration * tick / 4).toFixed(1)} ) })} {selected && ( )} {curves.map(curve => ( {points.length > 1 && ( `${x(point.center_seconds)},${y(point[curve.key])}`).join(' ')} fill="none" stroke={curve.color} strokeWidth="2.5" /> )} {points.map(point => ( onSelect(point)} className="curve-point" > {t('window.windowLabel', { index: point.index + 1 })} ·{' '} {formatSeconds(point.start_seconds)}–{formatSeconds(point.end_seconds)} ·{' '} {curve.label} {point[curve.key]} ))} ))} {t('window.axisTime')} {t('window.axisScore')}

{t('window.helpText')}

{points.map(point => ( ))}
{selected && result && (
{t('window.selectedWindow', { index: selected.index + 1 })}

{t('window.windowStart')} {formatSeconds(selected.start_seconds)} ·{' '} {t('window.windowEnd')} {formatSeconds(selected.end_seconds)} ·{' '} {t('window.windowCenter')} {formatSeconds(selected.center_seconds)} ·{' '} {t('window.windowBins')} {selected.feature_bins}

{curves.map(curve => (
{curve.label} {formatScore(selected[curve.key])}

{t('window.relativeTo', { delta: formatDelta(selected[curve.key], result[curve.key]) })}

))}
)} {(low < -1 || high > 1) && (

{t('window.rangeNote')}

)} )} {result && (
{t('window.exportNote')}
)}
) }