import { useParams, useNavigate } from 'react-router-dom' import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' import { vtlAPI, type TapeDrive, type VirtualTape } from '@/api/tape' import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { ArrowLeft, Trash2, Plus, Play, RefreshCw } from 'lucide-react' import { formatBytes } from '@/lib/format' import { useState } from 'react' export default function VTLDetail() { const { id } = useParams<{ id: string }>() const navigate = useNavigate() const queryClient = useQueryClient() const [selectedDrive, setSelectedDrive] = useState(null) const { data, isLoading } = useQuery({ queryKey: ['vtl-library', id], queryFn: () => vtlAPI.getLibrary(id!), enabled: !!id, }) const deleteMutation = useMutation({ mutationFn: () => vtlAPI.deleteLibrary(id!), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['vtl-libraries'] }) navigate('/tape') }, }) if (isLoading) { return
Loading library details...
} if (!data) { return
Library not found
} const { library, drives, tapes } = data return (
{/* Header */}

{library.name}

Virtual Tape Library • {library.slot_count} slots • {library.drive_count} drives

{/* Library Info */}
Library Status
Status: {library.is_active ? 'Active' : 'Inactive'}
mhVTL ID: {library.mhvtl_library_id}
Storage Path: {library.storage_path}
Capacity
Total Slots: {library.slot_count}
Used Slots: {tapes.length}
Free Slots: {library.slot_count - tapes.length}
Drives
Total Drives: {library.drive_count}
Idle: {drives.filter((d) => d.status === 'idle').length}
Ready: {drives.filter((d) => d.status === 'ready').length}
{/* Drives */}
Drives Virtual tape drives in this library
{drives.length > 0 ? (
{drives.map((drive) => ( setSelectedDrive(drive.id)} /> ))}
) : (

No drives configured

)}
{/* Tapes */}
Virtual Tapes {tapes.length} of {library.slot_count} slots used
{tapes.length > 0 ? (
{tapes.map((tape) => ( ))}
Barcode Slot Size Status Actions
{tape.barcode} {tape.slot_number} {formatBytes(tape.size_bytes)} {tape.status} {selectedDrive && ( )}
) : (

No tapes created yet

)}
) } interface DriveCardProps { drive: TapeDrive tapes: VirtualTape[] isSelected: boolean onSelect: () => void } function DriveCard({ drive, tapes, isSelected, onSelect }: DriveCardProps) { const currentTape = tapes.find((t) => t.id === drive.current_tape_id) return (

Drive {drive.drive_number}

{drive.status}
{currentTape ? (

Tape: {currentTape.barcode}

{formatBytes(currentTape.size_bytes)}

) : (

No tape loaded

)} {isSelected && (

Selected - Click tape to load

)}
) }