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 } from "lucide-react";
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 (
Total Time
{totalHours}h {totalMinutes}m
Total Sessions
{sessions.length}
Positions
{positions.map(position => (
{position}
))}
Session History
Date
Callsign
Position
Airport
Frequency
Duration
{sessions.map((session) => (
{format(new Date(session.logonTime), "MMM d, yyyy")}
{session.callsign}
{session.facilityType}
{session.airport}
{session.frequency}
{formatSessionDuration(session.logonTime, session.lastSeen)}
))}
);
}
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) => (
))}
);
}