Here's the updated component with the text labels positioned as requested:
"use client"
import React from "react"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
import { Separator } from "@/components/ui/separator"
import {
Play, Pause, Volume2, VolumeX,
Square, RotateCcw, Wifi, WifiOff,
RefreshCw, AlertTriangle
} from "lucide-react"
interface MediaControlsProps {
isPlaying: boolean
setIsPlaying: (value: boolean) => void
isMuted: boolean
setIsMuted: (value: boolean) => void
isHalted: boolean
setIsHalted: (value: boolean) => void
isConnected: boolean
setIsConnected: (value: boolean) => void
isSynced: boolean
setIsSynced: (value: boolean) => void
roomName?: string
lastEventTime?: number // in seconds
}
export function MediaControls({
isPlaying,
setIsPlaying,
isMuted,
setIsMuted,
isHalted,
setIsHalted,
isConnected,
setIsConnected,
isSynced,
setIsSynced,
roomName = "room 123",
lastEventTime = 169 // 2m49s default
}: MediaControlsProps) {
// Format time as mm:ss
const formatTime = (seconds: number): string => {
const minutes = Math.floor(seconds / 60);
const remainingSeconds = Math.floor(seconds % 60);
return `${minutes}m${remainingSeconds.toString().padStart(2, '0')}s`;
};
return (
<div className="flex flex-col w-full">
{/* Room info aligned right above the connection toggles */}
<div className="flex justify-between mb-1">
<div className="w-1/2"></div>
<div className="w-1/2 text-right">
<span className="text-xs text-muted-foreground font-medium">
chatting in {roomName}
</span>
</div>
</div>
{/* Main toggle controls */}
<div className="flex items-center space-x-2">
<ToggleGroup type="multiple" variant="outline" className="flex">
<ToggleGroupItem
value="play-pause"
aria-label={isPlaying ? "Pause" : "Play"}
pressed={isPlaying}
onClick={() => setIsPlaying(!isPlaying)}
>
{isPlaying ? <Pause className="h-4 w-4" /> : <Play className="h-4 w-4" />}
</ToggleGroupItem>
<ToggleGroupItem
value="mute-unmute"
aria-label={isMuted ? "Unmute" : "Mute"}
pressed={isMuted}
onClick={() => setIsMuted(!isMuted)}
>
{isMuted ? <VolumeX className="h-4 w-4" /> : <Volume2 className="h-4 w-4" />}
</ToggleGroupItem>
<ToggleGroupItem
value="halt-unhalt"
aria-label={isHalted ? "Resume" : "Halt"}
pressed={isHalted}
onClick={() => setIsHalted(!isHalted)}
>
{isHalted ? <RotateCcw className="h-4 w-4" /> : <Square className="h-4 w-4" />}
</ToggleGroupItem>
<Separator orientation="vertical" className="h-6" />
<ToggleGroupItem
value="connected-disconnected"
aria-label={isConnected ? "Connected" : "Disconnected"}
pressed={isConnected}
onClick={() => setIsConnected(!isConnected)}
>
{isConnected ? <Wifi className="h-4 w-4" /> : <WifiOff className="h-4 w-4" />}
</ToggleGroupItem>
<ToggleGroupItem
value="sync-out-of-sync"
aria-label={isSynced ? "In Sync" : "Out of Sync"}
pressed={isSynced}
onClick={() => setIsSynced(!isSynced)}
>
{isSynced ? <RefreshCw className="h-4 w-4" /> : <AlertTriangle className="h-4 w-4" />}
</ToggleGroupItem>
</ToggleGroup>
</div>
{/* Last event time below the media controls */}
<div className="flex justify-between mt-1">
<div className="w-1/2">
<span className="text-xs text-muted-foreground font-medium flex items-center">
last event <span className="ml-1 font-mono text-xs bg-muted px-1.5 py-0.5 rounded-md">{formatTime(lastEventTime)}</span>
</span>
</div>
<div className="w-1/2"></div>
</div>
</div>
)
}