import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuTrigger, } from '@/ui/components/ui/dropdown-menu' import { Slider } from '@/ui/components/ui/slider' import { cn } from '@/ui/lib/utils' import ProgressBar from '@/ui/components/viewers/progress-bar' import { formatTime, formatTimecode } from '@/ui/components/viewers/utils' import { useUiStore } from '@/ui/stores/ui' import type { MediaMetadata } from '@shumai/dtos' import { Download, Maximize, Minimize, Minus, Pause, Play, Plus, Repeat, Settings, Volume2, VolumeX, } from 'lucide-react' import type { PaneReportedState } from './types' const PLAYBACK_RATES = [0.5, 1, 1.5, 2] interface CompareControlBarProps { activeState: PaneReportedState | null previewUrl?: string metadata?: MediaMetadata startTimecode?: string | null isFullScreen: boolean onTogglePlay: () => void onToggleLoop: () => void onSeek: (frame: number) => void onVolumeChange: (volume: number) => void onToggleMute: () => void onChangePlaybackRate: (rate: number) => void onChangeResolution: (resolution: string) => void onZoomIn: () => void onZoomOut: () => void onFit: () => void onDownload: (key?: string) => void onToggleFullScreen: () => void } export function CompareControlBar({ activeState, previewUrl, metadata, startTimecode, isFullScreen, onTogglePlay, onToggleLoop, onSeek, onVolumeChange, onToggleMute, onChangePlaybackRate, onChangeResolution, onZoomIn, onZoomOut, onFit, onDownload, onToggleFullScreen, }: CompareControlBarProps) { const { videoTimeDisplayMode, setVideoTimeDisplayMode } = useUiStore() const fullscreenButton = ( ) const zoomControls = (
{Math.round((activeState?.zoom ?? 1) * 100)}%
) // Image (or unsupported) control bar if (!activeState || activeState.kind !== 'video' || !activeState.video) { return (
{activeState?.kind === 'image' && zoomControls} {activeState?.kind === 'image' && ( )} {fullscreenButton}
) } const video = activeState.video const displayTotalFrames = Math.max(0, video.totalFrames - 1) const displayString = videoTimeDisplayMode === 'frames' ? `${video.currentFrame} / ${displayTotalFrames} fr` : videoTimeDisplayMode === 'standard' ? `${formatTimecode(video.currentFrame, video.frameRate, 'standard')} / ${formatTime(video.totalFrames / video.frameRate)}` : `${formatTimecode(video.currentFrame, video.frameRate, videoTimeDisplayMode, startTimecode)} / ${formatTimecode(displayTotalFrames, video.frameRate, videoTimeDisplayMode, startTimecode)}` const cycleTimeDisplay = () => { const modes: Array<'standard' | 'timecode' | 'frames'> = ['standard', 'timecode', 'frames'] const idx = modes.indexOf(videoTimeDisplayMode as 'standard' | 'timecode' | 'frames') setVideoTimeDisplayMode(modes[(idx + 1) % modes.length]) } const previewResolutions = video.resolutions.filter((r) => !r.isRaw) return (
{/* Volume */}
onVolumeChange(vals[0] ?? 0)} className="w-20" />
{zoomControls} {/* Playback rate */} {video.playbackRate}x {PLAYBACK_RATES.map((rate) => ( onChangePlaybackRate(rate)} className={cn( 'px-2 py-1 text-xs', video.playbackRate === rate ? 'bg-primary text-primary-foreground' : 'text-foreground', )} > {rate}x ))} {/* Resolution */} {previewResolutions.length > 0 && ( {video.currentResolution} Quality {previewResolutions.map((res) => ( onChangeResolution(res.resolution)} className={cn( 'flex w-full items-center justify-between', video.currentResolution === res.resolution ? 'font-medium text-primary' : 'text-foreground', )} > {res.resolution} {res.width}x{res.height} ))} )} {/* Download */} Download {video.resolutions.map((res) => ( onDownload(res.key)} className="flex w-full items-center justify-between px-3 py-2 text-sm text-foreground" > {res.resolution} {res.isRaw ? 'RAW' : 'MP4'} ))} {fullscreenButton}
) }