File size: 5,137 Bytes
af980d7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | import { useState } from 'react';
import { motion } from 'framer-motion';
import { Film, AlertTriangle, CheckCircle, Clock } from 'lucide-react';
import styles from './TemporalTimeline.module.css';
const SEV_LABELS = { critical: 'Critical', high: 'High', medium: 'Medium' };
export default function TemporalTimeline({ timeline, duration = 23, totalFrames }) {
const [hovered, setHovered] = useState(null);
const durationSec = parseFloat(duration) || 23;
const toPercent = (sec) => (sec / durationSec) * 100;
const hasFlags = timeline.flaggedSegments.length > 0;
return (
<div className={styles.wrapper}>
<div className={styles.header}>
<div className={styles.headerLeft}>
<Film size={16} />
<span>Temporal Analysis Timeline</span>
</div>
<div className={styles.headerStats}>
<span className={styles.statChip}>
<span className={styles.chipDot} style={{ background: 'var(--ai-generated)' }} />
{timeline.flaggedSegments.length} flagged segments
</span>
<span className={styles.statChip}>
<span className={styles.chipDot} style={{ background: 'var(--authentic)' }} />
{timeline.cleanSegments.length} clean
</span>
</div>
</div>
{/* Main timeline bar */}
<div className={styles.timelineWrap}>
<div className={styles.timelineBar}>
{/* Clean segments */}
{timeline.cleanSegments.map((seg, i) => (
<div
key={i}
className={styles.segClean}
style={{
left: `${toPercent(seg.start)}%`,
width: `${toPercent(seg.end - seg.start)}%`,
}}
/>
))}
{/* Flagged segments */}
{timeline.flaggedSegments.map((seg, i) => (
<motion.div
key={i}
className={`${styles.segFlagged} ${styles['sev_' + seg.severity]}`}
style={{
left: `${toPercent(seg.start)}%`,
width: `${toPercent(seg.end - seg.start)}%`,
}}
initial={{ opacity: 0, scaleY: 0 }}
animate={{ opacity: 1, scaleY: 1 }}
transition={{ duration: 0.4, delay: i * 0.15 }}
onMouseEnter={() => setHovered(i)}
onMouseLeave={() => setHovered(null)}
>
{/* Tooltip */}
{hovered === i && (
<motion.div
className={styles.tooltip}
initial={{ opacity: 0, y: 4 }}
animate={{ opacity: 1, y: 0 }}
>
<p className={styles.tooltipTitle}>{seg.reason}</p>
<p className={styles.tooltipSub}>
{seg.start.toFixed(1)}s – {seg.end.toFixed(1)}s · {seg.frames.length} frames
</p>
<span className={`${styles.tooltipBadge} ${styles['badgeSev_' + seg.severity]}`}>
{SEV_LABELS[seg.severity]}
</span>
</motion.div>
)}
</motion.div>
))}
</div>
{/* Timestamp rulers */}
<div className={styles.rulers}>
{Array.from({ length: Math.ceil(durationSec / 5) + 1 }, (_, i) => i * 5).map(t => (
t <= durationSec && (
<div key={t} className={styles.rulerMark} style={{ left: `${toPercent(t)}%` }}>
<div className={styles.rulerLine} />
<span className={`${styles.rulerLabel} font-mono`}>{t}s</span>
</div>
)
))}
</div>
</div>
{/* Flagged segments list */}
<div className={styles.flagList}>
{hasFlags ? timeline.flaggedSegments.map((seg, i) => (
<motion.div
key={i}
className={`${styles.flagItem} ${styles['flagSev_' + seg.severity]}`}
initial={{ opacity: 0, x: -12 }}
animate={{ opacity: 1, x: 0 }}
transition={{ duration: 0.3, delay: i * 0.1 }}
>
<div className={`${styles.flagIcon} ${styles['flagIconSev_' + seg.severity]}`}>
<AlertTriangle size={13} />
</div>
<div className={styles.flagContent}>
<p className={styles.flagReason}>{seg.reason}</p>
<p className={styles.flagMeta}>
<Clock size={10} />
<span className="font-mono">{seg.start.toFixed(1)}s – {seg.end.toFixed(1)}s</span>
<span>·</span>
<span className="font-mono">{seg.frames.length} frames flagged</span>
</p>
</div>
<span className={`${styles.flagBadge} ${styles['badgeSev_' + seg.severity]}`}>
{SEV_LABELS[seg.severity]}
</span>
</motion.div>
)) : (
<div className={styles.emptyState}>
<CheckCircle size={16} />
<span>No suspicious temporal segments crossed the current threshold.</span>
</div>
)}
</div>
</div>
);
}
|