|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import Link from "next/link"; |
| 4 | +import { useMemo, useState } from "react"; |
| 5 | + |
| 6 | +function normalizeAirport(value) { |
| 7 | + return value.trim().toUpperCase(); |
| 8 | +} |
| 9 | + |
| 10 | +function includesAirport(list, airport) { |
| 11 | + if (!airport) { |
| 12 | + return true; |
| 13 | + } |
| 14 | + |
| 15 | + const normalized = normalizeAirport(airport); |
| 16 | + const stripped = normalized.startsWith("K") ? normalized.slice(1) : normalized; |
| 17 | + |
| 18 | + return list.some((code) => { |
| 19 | + const normalizedCode = normalizeAirport(code); |
| 20 | + if (normalizedCode === normalized) { |
| 21 | + return true; |
| 22 | + } |
| 23 | + |
| 24 | + if (normalizedCode.startsWith("K") && normalizedCode.slice(1) === stripped) { |
| 25 | + return true; |
| 26 | + } |
| 27 | + |
| 28 | + return normalizedCode === stripped; |
| 29 | + }); |
| 30 | +} |
| 31 | + |
| 32 | +function routeText(route) { |
| 33 | + return route.routeString || ""; |
| 34 | +} |
| 35 | + |
| 36 | +export default function AdarRoutesPage({ data }) { |
| 37 | + const [departure, setDeparture] = useState(""); |
| 38 | + const [arrival, setArrival] = useState(""); |
| 39 | + const [routeQuery, setRouteQuery] = useState(""); |
| 40 | + |
| 41 | + const normalizedRouteQuery = routeQuery.trim().toUpperCase(); |
| 42 | + |
| 43 | + const results = useMemo(() => { |
| 44 | + return (data.routes || []).filter((route) => { |
| 45 | + const departureMatch = includesAirport(route.departures || [], departure); |
| 46 | + const arrivalMatch = includesAirport(route.arrivals || [], arrival); |
| 47 | + const routeMatch = |
| 48 | + !normalizedRouteQuery || routeText(route).toUpperCase().includes(normalizedRouteQuery); |
| 49 | + |
| 50 | + return departureMatch && arrivalMatch && routeMatch; |
| 51 | + }); |
| 52 | + }, [arrival, data.routes, departure, normalizedRouteQuery]); |
| 53 | + |
| 54 | + const swapAirports = () => { |
| 55 | + setDeparture(arrival); |
| 56 | + setArrival(departure); |
| 57 | + }; |
| 58 | + |
| 59 | + return ( |
| 60 | + <main className="relative min-h-screen overflow-hidden px-6 py-8 md:px-10"> |
| 61 | + <div className="ambient-bg" /> |
| 62 | + <div className="mx-auto max-w-7xl space-y-6"> |
| 63 | + <header className="panel"> |
| 64 | + <div className="flex items-start justify-between gap-3"> |
| 65 | + <p className="text-accent text-sm font-semibold uppercase tracking-[0.24em]">Reference</p> |
| 66 | + <Link className="button-secondary text-sm" href="/"> |
| 67 | + Back to Toolkit |
| 68 | + </Link> |
| 69 | + </div> |
| 70 | + <h1 className="font-heading text-main mt-1 text-4xl font-bold tracking-wide md:text-5xl"> |
| 71 | + ADAR Route Lookup |
| 72 | + </h1> |
| 73 | + <p className="text-muted mt-2 max-w-4xl"> |
| 74 | + Search adapted departure/arrival routes by airport pair. This view uses parsed ERAM ADAR |
| 75 | + adaptation data. |
| 76 | + </p> |
| 77 | + |
| 78 | + <div className="mt-5 grid gap-3 lg:grid-cols-[1fr_auto_1fr_1fr]"> |
| 79 | + <label className="space-y-1"> |
| 80 | + <span className="text-muted text-xs uppercase tracking-[0.16em]">Departure</span> |
| 81 | + <input |
| 82 | + className="search w-full" |
| 83 | + list="adar-airports" |
| 84 | + onChange={(event) => setDeparture(event.target.value)} |
| 85 | + placeholder="KIAH or IAH" |
| 86 | + type="search" |
| 87 | + value={departure} |
| 88 | + /> |
| 89 | + </label> |
| 90 | + |
| 91 | + <div className="flex items-end"> |
| 92 | + <button className="button-secondary w-full" onClick={swapAirports} type="button"> |
| 93 | + Swap |
| 94 | + </button> |
| 95 | + </div> |
| 96 | + |
| 97 | + <label className="space-y-1"> |
| 98 | + <span className="text-muted text-xs uppercase tracking-[0.16em]">Arrival</span> |
| 99 | + <input |
| 100 | + className="search w-full" |
| 101 | + list="adar-airports" |
| 102 | + onChange={(event) => setArrival(event.target.value)} |
| 103 | + placeholder="KAUS or AUS" |
| 104 | + type="search" |
| 105 | + value={arrival} |
| 106 | + /> |
| 107 | + </label> |
| 108 | + |
| 109 | + <label className="space-y-1"> |
| 110 | + <span className="text-muted text-xs uppercase tracking-[0.16em]">Route Contains</span> |
| 111 | + <input |
| 112 | + className="search w-full" |
| 113 | + onChange={(event) => setRouteQuery(event.target.value)} |
| 114 | + placeholder="DRLLR5, V568, SAT" |
| 115 | + type="search" |
| 116 | + value={routeQuery} |
| 117 | + /> |
| 118 | + </label> |
| 119 | + </div> |
| 120 | + |
| 121 | + <datalist id="adar-airports"> |
| 122 | + {(data.airports || []).map((airport) => ( |
| 123 | + <option key={airport} value={airport} /> |
| 124 | + ))} |
| 125 | + </datalist> |
| 126 | + |
| 127 | + <div className="mt-4 flex flex-wrap gap-2 text-xs uppercase tracking-[0.14em]"> |
| 128 | + <span className="border-default bg-surface-soft text-muted rounded-full border px-3 py-1"> |
| 129 | + {data.meta.routeCount} routes |
| 130 | + </span> |
| 131 | + <span className="border-default bg-surface-soft text-muted rounded-full border px-3 py-1"> |
| 132 | + {data.meta.airportCount} airports |
| 133 | + </span> |
| 134 | + <span className="border-default bg-surface-soft text-muted rounded-full border px-3 py-1"> |
| 135 | + {results.length} matches |
| 136 | + </span> |
| 137 | + </div> |
| 138 | + </header> |
| 139 | + |
| 140 | + <section className="panel"> |
| 141 | + {results.length === 0 ? ( |
| 142 | + <p className="text-muted">No matching ADAR records for this filter combination.</p> |
| 143 | + ) : ( |
| 144 | + <div className="overflow-x-auto"> |
| 145 | + <table className="adar-table min-w-full text-sm"> |
| 146 | + <thead className="bg-surface-soft"> |
| 147 | + <tr> |
| 148 | + <th>ID</th> |
| 149 | + <th>Departure</th> |
| 150 | + <th>Arrival</th> |
| 151 | + <th>Route</th> |
| 152 | + <th>AC Criteria</th> |
| 153 | + <th>Altitudes</th> |
| 154 | + </tr> |
| 155 | + </thead> |
| 156 | + <tbody> |
| 157 | + {results.map((route) => ( |
| 158 | + <tr key={route.adarId}> |
| 159 | + <td className="font-mono font-semibold">{route.adarId}</td> |
| 160 | + <td>{(route.departures || []).join(", ")}</td> |
| 161 | + <td>{(route.arrivals || []).join(", ")}</td> |
| 162 | + <td className="font-mono">{routeText(route)}</td> |
| 163 | + <td> |
| 164 | + {(route.aircraftCriteriaDetails || []).length === 0 |
| 165 | + ? "N/A" |
| 166 | + : route.aircraftCriteriaDetails |
| 167 | + .map((criteria) => { |
| 168 | + const suffix = criteria.isExcluded ? " (Excluded)" : ""; |
| 169 | + return `${criteria.id} (${criteria.facility})${suffix}`; |
| 170 | + }) |
| 171 | + .join(", ")} |
| 172 | + </td> |
| 173 | + <td> |
| 174 | + {route.lowerAltitude}-{route.upperAltitude} |
| 175 | + </td> |
| 176 | + </tr> |
| 177 | + ))} |
| 178 | + </tbody> |
| 179 | + </table> |
| 180 | + </div> |
| 181 | + )} |
| 182 | + </section> |
| 183 | + </div> |
| 184 | + </main> |
| 185 | + ); |
| 186 | +} |
| 187 | + |
0 commit comments