import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Skeleton } from "@/components/ui/skeleton"; import { Card } from "@/components/ui/card"; import { formatDistanceToNow, format } from "date-fns"; import { Clock, Calendar, Radio, Star } from "lucide-react"; const ratings = { "-1": "INA", "0": "SUS", "1": "OBS", "2": "S1", "3": "S2", "4": "S3", "5": "C1", "6": "C2", "7": "C3", "8": "I1", "9": "I2", "10": "I3", "11": "SUP", "12": "ADM", } interface ControllerProfileProps { sessions: any[]; loading: boolean; } export function ControllerProfile({ sessions, loading }: ControllerProfileProps) { if (loading) { return ; } const totalTime = sessions.reduce((acc, session) => { const duration = new Date(session.lastSeen).getTime() - new Date(session.logonTime).getTime(); return acc + duration; }, 0); const totalHours = Math.floor(totalTime / (1000 * 60 * 60)); const totalMinutes = Math.floor((totalTime % (1000 * 60 * 60)) / (1000 * 60)); // Get unique positions const positions = [...new Set(sessions.map(s => s.facilityType))]; return (
{[ { icon: , title: "Total Time", value: `${totalHours}h ${totalMinutes}m`, }, { icon: , title: "Total Sessions", value: sessions.length, }, { icon: , title: "Positions", value: (
{positions.map(position => ( {position} ))}
), }, { icon:

Session History

Date Callsign Position Airport Frequency Duration Rating {sessions.map((session) => ( {format(new Date(session.logonTime), "MMM d, yyyy")} {session.callsign} {session.facilityType} {session.airport} {session.frequency} {formatSessionDuration(session.logonTime, session.lastSeen)} {session.rating} ))}
); } function formatSessionDuration(start: string, end: string) { const duration = new Date(end).getTime() - new Date(start).getTime(); const hours = Math.floor(duration / (1000 * 60 * 60)); const minutes = Math.floor((duration % (1000 * 60 * 60)) / (1000 * 60)); return `${hours}h ${minutes}m`; } function LoadingSkeleton() { return (
{Array.from({ length: 5 }).map((_, i) => (
))}
); }