import { Minus, Plus, Radio, Settings, Users, Volume2, VolumeX } from "lucide-react" import { useState } from "react" import { useTranslation } from "react-i18next" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { Slider } from "@/components/ui/slider" import { cn } from "@/lib/utils" import { AudioBus, ChannelGroup, ChannelSend } from "../../services/bus-router" interface RoutingMatrixProps { buses: AudioBus[] groups: ChannelGroup[] sends: ChannelSend[] channelIds: string[] onCreateBus: (name: string, type: AudioBus["type"]) => void onCreateGroup: (name: string, channelIds: string[], color: string) => void onCreateSend: (sourceChannelId: string, destinationBusId: string, level: number) => void onAssignChannelToBus: (channelId: string, busId: string) => void onUpdateSendLevel: (sendId: string, level: number) => void onSetBusMute: (busId: string, muted: boolean) => void onSetBusSolo: (busId: string, solo: boolean) => void onSetGroupMute: (groupId: string, muted: boolean) => void onSetGroupSolo: (groupId: string, solo: boolean) => void onDeleteBus: (busId: string) => void onDeleteGroup: (groupId: string) => void } export function RoutingMatrix({ buses, groups, sends, channelIds, onCreateBus, onCreateGroup, onCreateSend, onAssignChannelToBus, onUpdateSendLevel, onSetBusMute, onSetBusSolo, onSetGroupMute, onSetGroupSolo, onDeleteBus, onDeleteGroup, }: RoutingMatrixProps) { const { t } = useTranslation() const [newBusName, setNewBusName] = useState("") const [newBusType, setNewBusType] = useState("stereo") const [newGroupName, setNewGroupName] = useState("") const [selectedChannels, setSelectedChannels] = useState([]) const [showSends, setShowSends] = useState(false) const handleCreateBus = () => { if (newBusName.trim()) { onCreateBus(newBusName.trim(), newBusType) setNewBusName("") } } const handleCreateGroup = () => { if (newGroupName.trim() && selectedChannels.length > 0) { onCreateGroup(newGroupName.trim(), selectedChannels, "#3b82f6") setNewGroupName("") setSelectedChannels([]) } } const getChannelSends = (channelId: string) => { return sends.filter((send) => send.sourceChannelId === channelId) } return (
{/* Header */}

{t("fairlightAudio.routingMatrix.title")}

{/* Left Panel - Buses and Groups */}
{/* Buses Section */}

{t("fairlightAudio.routingMatrix.audioBuses")}

{/* Create Bus */}
setNewBusName(e.target.value)} className="h-8" />
{/* Bus List */}
{buses.map((bus) => (
{bus.name}
{bus.type}
{bus.id !== "master" && ( )}
))}
{/* Groups Section */}

{t("fairlightAudio.routingMatrix.channelGroups")}

{/* Create Group */}
setNewGroupName(e.target.value)} className="h-8" />
{t("fairlightAudio.routingMatrix.selectChannels")}
{channelIds.map((channelId) => ( ))}
{/* Group List */}
{groups.map((group) => (
{group.name}
Channels: {group.channelIds.join(", ")}
Bus: {group.busId}
))}
{/* Right Panel - Routing Matrix */}
{showSends ? ( /* Sends Matrix */

{t("fairlightAudio.routingMatrix.sendMatrix")}

{buses .filter((bus) => bus.id !== "master") .map((bus) => ( ))} {channelIds.map((channelId) => ( {buses .filter((bus) => bus.id !== "master") .map((bus) => { const existingSend = sends.find( (send) => send.sourceChannelId === channelId && send.destinationBusId === bus.id, ) return ( ) })} ))}
{t("fairlightAudio.routingMatrix.channel")} {bus.name}
{channelId} {existingSend ? (
onUpdateSendLevel(existingSend.id, value / 100)} min={0} max={100} step={1} className="w-16 mx-auto" />
{Math.round(existingSend.level * 100)}%
) : ( )}
) : ( /* Channel Assignment Matrix */

{t("fairlightAudio.routingMatrix.channelBusAssignment")}

{channelIds.map((channelId) => (
{channelId}
{t("fairlightAudio.routingMatrix.sendsCount")} {getChannelSends(channelId).length}
))}
)}
) }