import { useEffect, useRef, useState } from 'react' import { Play, Pause, SkipBack, SkipForward, History } from 'lucide-react' import { usePlaybackStore, REPLAY_TICKS, REPLAY_START, REPLAY_END } from '@/store/playbackStore' import { useSituationStore } from '@/store/situationStore' import { NewsTicker } from './NewsTicker' import { config } from '@/config' /** 冲突开始时间:2月28日凌晨 03:00(本地时间) */ const CONFLICT_START = new Date(2026, 1, 28, 3, 0, 0, 0) function formatTick(iso: string): string { const d = new Date(iso) return d.toLocaleString('zh-CN', { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false, }) } function getConflictDuration(toTime: Date): { days: number; hours: number } { const diffMs = toTime.getTime() - CONFLICT_START.getTime() if (diffMs <= 0) return { days: 0, hours: 0 } const days = Math.floor(diffMs / (24 * 60 * 60 * 1000)) const hours = Math.floor((diffMs % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000)) return { days, hours } } export function TimelinePanel() { const situation = useSituationStore((s) => s.situation) const [now, setNow] = useState(() => new Date()) const { isReplayMode, playbackTime, isPlaying, speedSecPerTick, setReplayMode, setPlaybackTime, setIsPlaying, stepForward, stepBack, setSpeed, } = usePlaybackStore() const timerRef = useRef | null>(null) useEffect(() => { const t = setInterval(() => setNow(new Date()), 1000) return () => clearInterval(t) }, []) const toTime = isReplayMode ? new Date(playbackTime) : now const conflictDuration = getConflictDuration(toTime) useEffect(() => { if (!isPlaying || !isReplayMode) { if (timerRef.current) { clearInterval(timerRef.current) timerRef.current = null } return } timerRef.current = setInterval(() => { const current = usePlaybackStore.getState().playbackTime const i = REPLAY_TICKS.indexOf(current) if (i >= REPLAY_TICKS.length - 1) { setIsPlaying(false) return } setPlaybackTime(REPLAY_TICKS[i + 1]) }, speedSecPerTick * 1000) return () => { if (timerRef.current) clearInterval(timerRef.current) } }, [isPlaying, isReplayMode, speedSecPerTick, setPlaybackTime, setIsPlaying]) const index = REPLAY_TICKS.indexOf(playbackTime) const value = index >= 0 ? index : REPLAY_TICKS.length - 1 const handleSliderChange = (e: React.ChangeEvent) => { const i = parseInt(e.target.value, 10) setPlaybackTime(REPLAY_TICKS[i]) } return (
{!isReplayMode && (
冲突已持续 {conflictDuration.days} 天 {conflictDuration.hours} 小时
)}
{!isReplayMode && config.showNewsTicker && (
)} {isReplayMode && ( <>
{formatTick(REPLAY_START)} {formatTick(playbackTime)} {formatTick(REPLAY_END)}
)}
) }