"use client"; import { useState, Fragment } from "react"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Skeleton } from "@/components/ui/skeleton"; import { ChevronDown, ChevronUp, Plane, PlaneLanding, PlaneTakeoff } from "lucide-react"; interface Flight { callsign: string; type: 'Departure' | 'Arrival'; time: string; route: string; origin: string; destination: string; } interface MetarTableProps { data: any[]; loading: boolean; } export function MetarTable({ data, loading }: MetarTableProps) { const [expandedAirport, setExpandedAirport] = useState(null); const [flights, setFlights] = useState([]); const [loadingFlights, setLoadingFlights] = useState(false); const handleAirportClick = async (airport: string) => { if (expandedAirport === airport) { setExpandedAirport(null); return; } setExpandedAirport(airport); setLoadingFlights(true); try { const response = await fetch(`/api/vatsim/${airport}`); const data = await response.json(); setFlights(data); } catch (error) { console.error('Failed to fetch flights:', error); } finally { setLoadingFlights(false); } }; if (loading) { return ; } return ( Airport Conditions RWY Wind (°/kts) Headwind (kts) Xwind (kts) Altimeter METAR {data.map((row, index) => ( handleAirportClick(row.airport)} > {expandedAirport === row.airport ? ( ) : ( )} {row.airport} {row.flightRules} {row.bestRunway} {row.wind} {row.headwind} {row.crosswind} {row.altimeter} {row.metar} {expandedAirport === row.airport && ( {loadingFlights ? (
) : flights.length > 0 ? (

Active Flights

{flights.map((flight, i) => (
{flight.type === 'Departure' ? ( ) : ( )} {flight.callsign}

{flight.type}: {flight.time}Z

{flight.origin} → {flight.destination}

{flight.route}

))}
) : (

No active flights found for {row.airport}

)}
)}
))}
); } function LoadingSkeleton() { return (
{Array.from({ length: 5 }).map((_, i) => (
))}
); }