import { PropsWithChildren } from 'react'; import { Tooltip } from '@chakra-ui/react'; import { Playback, TimerPhase } from 'ontime-types'; import { dayInMs, millisToString } from 'ontime-utils'; import { useTimer } from '../../../../common/hooks/useSocket'; import { formatDuration } from '../../../../common/utils/time'; import TimerDisplay from '../timer-display/TimerDisplay'; import style from './PlaybackTimer.module.scss'; interface PlaybackTimerProps { playback: Playback; } function resolveAddedTimeLabel(addedTime: number) { if (addedTime > 0) { return `Added ${formatDuration(addedTime, false)}`; } if (addedTime < 0) { return `Removed ${formatDuration(Math.abs(addedTime), false)}`; } return ''; } export default function PlaybackTimer(props: PropsWithChildren) { const { playback, children } = props; const timer = useTimer(); const started = millisToString(timer.startedAt); const expectedFinish = timer.expectedFinish !== null ? timer.expectedFinish % dayInMs : null; const finish = millisToString(expectedFinish); const isRolling = playback === Playback.Roll; const isWaiting = timer.phase === TimerPhase.Pending; const isOvertime = timer.phase === TimerPhase.Overtime; const hasAddedTime = Boolean(timer.addedTime); const rollLabel = isRolling ? 'Roll mode active' : ''; const addedTimeLabel = resolveAddedTimeLabel(timer.addedTime); return (
{isWaiting ? ( Roll: Countdown to start ) : ( <> Started at {started} Expect end {finish} )}
{children}
); }