UNPKG

a429-flight-display

Version:

React components for ARINC 429 Flight Display with primary flight instruments

2 lines (1 loc) 33.4 kB
(function(d,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],t):(d=typeof globalThis<"u"?globalThis:d||self,t(d.A429FlightDisplay={},d.React,d.React))})(this,function(d,t,b){"use strict";var fe=Object.defineProperty;var xe=(d,t,b)=>t in d?fe(d,t,{enumerable:!0,configurable:!0,writable:!0,value:b}):d[t]=b;var v=(d,t,b)=>xe(d,typeof t!="symbol"?t+"":t,b);let L=class{constructor(r,n,o,a){v(this,"label");v(this,"sdi");v(this,"data");v(this,"ssm");v(this,"parity");this.label=r,this.sdi=n,this.data=o,this.ssm=a,this.parity=this.calculateParity()}calculateParity(){const r=this.label<<24|this.sdi<<22|this.data<<3|this.ssm<<1;let n=0;for(let o=0;o<31;o++)r&1<<o&&n++;return n%2===0?1:0}};const M={ALTITUDE:131,AIRSPEED:134,MACH:135,HEADING:146,VERTICAL_SPEED:245,PITCH:212,ROLL:213,TEMPERATURE:137},S={NORMAL_OPERATION:3};function I(e,r=1,n,o=0){const a=Math.round(e*r)&524287;return new L(n,o,a,S.NORMAL_OPERATION)}const B=({flightData:e})=>{const r=()=>[new L(M.ALTITUDE,0,Math.round(e.altitude),S.NORMAL_OPERATION),new L(M.AIRSPEED,0,Math.round(e.airspeed),S.NORMAL_OPERATION),new L(M.MACH,0,Math.round(e.mach*1e5),S.NORMAL_OPERATION),new L(M.HEADING,0,Math.round(e.true_heading),S.NORMAL_OPERATION),new L(M.VERTICAL_SPEED,0,Math.round(e.vertical_speed),S.NORMAL_OPERATION),new L(M.PITCH,0,Math.round(e.pitch_angle*100),S.NORMAL_OPERATION),new L(M.ROLL,0,Math.round(e.roll_angle*100),S.NORMAL_OPERATION)];return t.jsxs("div",{className:"bg-gray-900 rounded-xl p-6 shadow-2xl",children:[t.jsxs("div",{className:"flex justify-between items-center mb-4",children:[t.jsx("h2",{className:"text-xl font-bold text-white",children:"Live ARINC 429 Data Bus"}),t.jsx("div",{className:"text-green-400 font-mono text-sm",children:e.timestamp.toLocaleTimeString()})]}),t.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:r().map((n,o)=>{const a=Object.keys(M).find(s=>M[s]===n.label),l="0x"+(n.label<<24|n.sdi<<22|n.data<<3|n.ssm<<1|n.parity).toString(16).toUpperCase().padStart(8,"0");return t.jsxs("div",{className:"bg-gray-800 rounded-lg p-4 border border-gray-600",children:[t.jsx("div",{className:"text-yellow-400 font-semibold text-sm mb-2",children:a}),t.jsxs("div",{className:"text-white font-mono text-xs space-y-1",children:[t.jsxs("div",{children:["Label: ",n.label.toString(8).padStart(3,"0")]}),t.jsxs("div",{children:["Data: ",n.data]}),t.jsxs("div",{children:["Hex: ",l]})]}),t.jsx("div",{className:"text-green-400 text-xs mt-2",children:"● NORMAL"})]},o)})}),t.jsx("div",{className:"mt-6 text-center",children:t.jsxs("div",{className:"inline-flex items-center space-x-4 bg-gray-800 px-6 py-3 rounded-lg",children:[t.jsx("div",{className:"w-3 h-3 bg-green-400 rounded-full animate-pulse"}),t.jsx("span",{className:"text-white font-semibold",children:"ARINC 429 Bus Active"}),t.jsx("span",{className:"text-gray-400 font-mono text-sm",children:"12.5 kHz"})]})})]})},Y=({pitch:e,roll:r})=>{const o=()=>{const l=[];for(let s=-30;s<=30;s+=5){if(s===0)continue;const i=s%10===0;l.push(t.jsx("div",{className:"absolute flex items-center justify-center w-full",children:t.jsxs("div",{className:"flex items-center justify-center",style:{transform:`translateY(${-s*3}px)`},children:[t.jsx("div",{className:`bg-white ${i?"h-0.5 w-16":"h-0.5 w-8"}`}),i&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-white text-xs font-mono ml-2 select-none",children:Math.abs(s)}),t.jsx("div",{className:"bg-white h-0.5 w-16 ml-2"}),t.jsx("span",{className:"text-white text-xs font-mono ml-2 select-none",children:Math.abs(s)})]})]})},s))}return l},a=()=>{const l=[];return[-60,-45,-30,-20,-10,0,10,20,30,45,60].forEach(i=>{const c=[0,-30,30,-60,60].includes(i),h=[-10,-20,10,20,-45,45].includes(i);l.push(t.jsxs("div",{className:"absolute top-1 left-1/2 origin-bottom transform -translate-x-1/2",style:{transform:`translateX(-50%) rotate(${i}deg)`,transformOrigin:"center 92px"},children:[t.jsx("div",{className:`bg-white ${c?"w-0.5 h-4":h?"w-0.5 h-3":"w-0.5 h-2"}`}),(i===-30||i===30||i===-60||i===60)&&t.jsx("div",{className:"text-white text-xs font-mono text-center mt-1 select-none",children:Math.abs(i)})]},i))}),l};return t.jsxs("div",{className:"relative w-48 h-48 rounded-full overflow-hidden border-4 border-gray-600 shadow-2xl bg-gray-900",children:[t.jsxs("div",{className:"absolute inset-0 bg-gradient-to-b from-sky-400 via-sky-300 to-amber-500",style:{transform:`rotate(${r}deg) translateY(${e*3}px)`,transformOrigin:"center center",width:"200%",height:"200%",left:"-50%",top:"-50%"},children:[t.jsx("div",{className:"absolute left-0 right-0 h-1 bg-white",style:{top:"50%",transform:"translateY(-50%)"}}),t.jsx("div",{className:"absolute inset-0 flex justify-center items-center",style:{top:"50%",left:"50%",transform:"translate(-50%, -50%)"},children:o()})]}),t.jsx("div",{className:"absolute inset-0",children:a()}),t.jsx("div",{className:"absolute top-1 left-1/2 w-0 h-0 border-l-3 border-r-3 border-b-6 border-transparent border-b-yellow-400 transform -translate-x-1/2 z-20",style:{transform:`translateX(-50%) rotate(${r}deg)`,transformOrigin:"center 92px"}}),t.jsx("div",{className:"absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 z-30",children:t.jsxs("div",{className:"relative flex items-center justify-center",children:[t.jsx("div",{className:"w-12 h-1 bg-yellow-400"}),t.jsx("div",{className:"absolute w-1 h-6 bg-yellow-400"}),t.jsx("div",{className:"absolute w-2 h-2 bg-yellow-400 rounded-full"})]})}),t.jsx("div",{className:"absolute top-2 left-1/2 w-0 h-0 border-l-2 border-r-2 border-b-4 border-transparent border-b-white transform -translate-x-1/2 z-10"})]})},K=({value:e,title:r,unit:n,unitTooltip:o,generateMarks:a,getValueColor:l=()=>"text-white",isMajorTick:s=p=>p%20===0,formatValue:i=p=>p.toString(),formatCurrentValue:c=p=>Math.round(p).toString(),pixelsPerUnit:h=2,pointerSide:f="right",className:m=""})=>{const p=a(e),w=f==="left";return console.log(),t.jsxs("div",{className:`bg-gray-900 text-white rounded-lg w-32 h-64 relative overflow-hidden border-2 border-gray-600 flex flex-col ${m}`,children:[t.jsx("div",{className:"text-center text-xs font-bold text-gray-300 py-1 border-b border-gray-600",children:r}),t.jsxs("div",{className:"flex-1 relative overflow-hidden",children:[t.jsx("div",{className:"absolute inset-0 flex flex-col justify-center",children:t.jsx("div",{className:"relative h-48 mx-2",children:p.map(y=>{const x=(e-y)*h,_=96+x;if(Math.abs(x)>90||_<0||_>202)return null;const A=s(y);return t.jsxs("div",{className:"absolute flex items-center w-full",style:{top:`${_}px`,transform:"translateY(-50%)",flexDirection:w?"row-reverse":"row"},children:[A&&t.jsx("div",{className:`text-xs font-mono w-8 ${w?"text-left":"text-right"} ${l(y)}`,children:i(y)}),t.jsx("div",{className:`${w?"mr-1":"ml-1"} bg-white ${A?"h-0.5 w-4":"h-0.5 w-2"}`})]},y)})})}),t.jsx("div",{className:`absolute ${w?"left-2":"right-2"} top-1/2 w-0 h-0 ${w?"border-t-4 border-b-4 border-r-6 border-transparent border-r-yellow-400":"border-t-4 border-b-4 border-l-6 border-transparent border-l-yellow-400"} transform -translate-y-1/2 z-20`}),t.jsx("div",{className:`absolute top-1/2 ${w?"left-8":"right-8"} bg-black px-2 py-1 border border-white text-yellow-400 font-bold text-sm transform -translate-y-1/2 z-10 min-w-[3rem] text-center`,children:c(e)})]}),t.jsxs("div",{className:"relative group text-center text-xs text-gray-300 py-1 border-t border-gray-600",children:[t.jsx("span",{className:"cursor-help",children:n}),o&&t.jsxs("div",{className:"absolute bottom-full left-1/2 transform -translate-x-1/2 mb-2 px-2 py-1 bg-gray-800 text-white text-xs rounded shadow-lg opacity-0 group-hover:opacity-100 transition-opacity duration-200 z-50 pointer-events-none max-w-32 text-center whitespace-normal",children:[o,t.jsx("div",{className:"absolute top-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-l-2 border-r-2 border-t-2 border-transparent border-t-gray-800"})]})]})]})},q=({airspeed:e,options:r})=>{const n=l=>{const s=[],h=Math.max(0,Math.floor((l-100)/10)*10),f=Math.ceil((l+100)/10)*10;for(let m=h;m<=f;m+=10)s.push(m);return s},o=l=>{const s=[{min:40,max:100,color:"text-white"},{min:100,max:180,color:"text-green-400"},{min:180,max:220,color:"text-yellow-400"},{min:220,max:1/0,color:"text-red-400"}],i=(r==null?void 0:r.speedColorRanges)||s;for(const c of i)if(l>=c.min&&l<=c.max)return c.color;return"text-gray-400"},a=l=>l%20===0;return t.jsx(K,{value:e,title:"AIRSPEED",unit:"KTS",unitTooltip:"Knots (nautical mph)",generateMarks:n,getValueColor:o,isMajorTick:a,pixelsPerUnit:2,pointerSide:"right"})},X=({altitude:e})=>{const r=l=>{const s=[],h=Math.max(0,Math.floor((l-5e3)/100)*100),f=Math.ceil((l+5e3)/100)*100;for(let m=h;m<=f;m+=100)s.push(m);return s},n=l=>l<1e3?"text-red-400":l>=1e3&&l<=1e4?"text-white":l>1e4&&l<=4e4?"text-green-400":l>4e4?"text-yellow-400":"text-gray-400",o=l=>l%500===0,a=l=>l.toString();return t.jsx(K,{value:e,title:"ALTITUDE",unit:"FT",unitTooltip:"Feet above sea level",generateMarks:r,getValueColor:n,isMajorTick:o,formatValue:a,pixelsPerUnit:.1,pointerSide:"left"})},J=({heading:e})=>{const n=(()=>{const s=[];for(let i=0;i<72;i++){const c=i*5,h=c%90===0,f=c%30===0,m=c%10===0;let p="";c===0?p="N":c===90?p="E":c===180?p="S":c===270?p="W":f&&(p=(c/10).toString().padStart(2,"0")),s.push({angle:c,label:p,isCardinal:h,isMajor:f,isMinor:m,x:i*4})}return s})(),o=(e%360+360)%360,l=96-o*4;return t.jsxs("div",{className:"bg-gray-900 text-white rounded-lg w-48 h-16 relative overflow-hidden border-2 border-gray-600 shadow-lg",children:[t.jsx("div",{className:"absolute top-0 left-1/2 w-0 h-0 border-l-3 border-r-3 border-b-6 border-transparent border-b-yellow-400 transform -translate-x-1/2 z-10"}),t.jsx("div",{className:"absolute top-1 flex transition-transform duration-200 ease-out",style:{transform:`translateX(${l}px)`},children:n.concat(n).concat(n).map((s,i)=>t.jsxs("div",{className:"relative flex flex-col items-center",style:{width:"4px"},children:[t.jsx("div",{className:`bg-white ${s.isCardinal?"w-0.5 h-4":s.isMajor?"w-0.5 h-3":s.isMinor?"w-px h-2":"w-px h-1"}`}),s.label&&t.jsx("div",{className:`mt-0.5 text-xs font-mono whitespace-nowrap ${s.isCardinal?"text-yellow-400 font-bold":"text-white"}`,style:{fontSize:"10px"},children:s.label})]},i))}),t.jsxs("div",{className:"absolute bottom-1 left-1/2 bg-black px-2 py-0.5 border border-gray-400 text-green-400 font-bold text-xs transform -translate-x-1/2 rounded whitespace-nowrap",children:["HDG ",Math.round(o).toString().padStart(3,"0"),"°"]}),t.jsx("div",{className:"absolute top-0 left-0 w-4 h-full bg-gradient-to-r from-gray-900 to-transparent pointer-events-none z-20"}),t.jsx("div",{className:"absolute top-0 right-0 w-4 h-full bg-gradient-to-l from-gray-900 to-transparent pointer-events-none z-20"})]})},Q=({verticalSpeed:e})=>{const n=(()=>{const s=[];for(let h=-3e3;h<=3e3;h+=200){const f=50-h/3e3*40,m=h%1e3===0,p=m;s.push({value:h,yPercent:f,isMajor:m,showLabel:p,label:p?(h/1e3).toString():""})}return s})(),a=50-Math.max(-3e3,Math.min(3e3,e))/3e3*40,l=()=>{const s=Math.abs(e);return s<50?"00":Math.floor(s/100).toString().padStart(2,"0")};return t.jsxs("div",{className:"bg-gray-900 text-white rounded-lg w-20 h-64 relative border-2 border-gray-600 shadow-lg overflow-hidden",children:[t.jsx("div",{className:"absolute top-1 left-1/2 transform -translate-x-1/2 text-xs font-mono text-gray-300 font-semibold",children:"V/S"}),t.jsx("div",{className:"absolute right-1 top-8 bottom-8 w-16",children:n.map((s,i)=>t.jsxs("div",{className:"absolute w-full flex items-center justify-end",style:{top:`${s.yPercent}%`},children:[s.showLabel&&t.jsx("div",{className:"mr-1 text-xs font-mono text-white",children:s.label}),t.jsx("div",{className:`bg-white h-0.5 ${s.isMajor?"w-4":"w-2"} ${s.value===0?"bg-yellow-400 w-6":"bg-white"}`})]},i))}),t.jsx("div",{className:"absolute left-2 top-1/2 w-0 h-0 border-t-2 border-b-2 border-r-4 border-transparent border-r-yellow-400 transform -translate-y-1/2 z-10"}),t.jsx("div",{className:"absolute left-8 w-6 h-0.5 bg-cyan-400 transform -translate-y-1/2 transition-all duration-300 z-20",style:{top:`${a}%`}}),t.jsxs("div",{className:"absolute left-1/2 top-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-black px-2 py-1 border border-gray-400 rounded z-30",children:[t.jsx("div",{className:"text-cyan-400 font-bold text-lg font-mono",children:l()}),t.jsx("div",{className:"text-gray-400 text-xs text-center",children:e>=0?"▲":"▼"})]}),t.jsx("div",{className:"absolute bottom-1 left-1/2 transform -translate-x-1/2 text-xs text-gray-400 font-mono",children:"FPM"}),t.jsx("div",{className:"absolute top-0 left-0 w-full h-8 bg-gradient-to-b from-gray-900 to-transparent pointer-events-none z-40"}),t.jsx("div",{className:"absolute bottom-0 left-0 w-full h-8 bg-gradient-to-t from-gray-900 to-transparent pointer-events-none z-40"})]})};function te({flightData:e}){return t.jsx(t.Fragment,{children:t.jsxs("div",{className:"bg-black rounded-xl p-8 shadow-2xl mb-6",children:[t.jsxs("div",{className:"flex justify-center items-center space-x-8",children:[t.jsx("p",{children:"AirSpeed"}),t.jsx(q,{airspeed:e.airspeed}),t.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[t.jsx(Y,{pitch:e.pitch_angle,roll:e.roll_angle}),t.jsx(J,{heading:e.true_heading})]}),t.jsx(X,{altitude:e.altitude}),t.jsx(Q,{verticalSpeed:e.vertical_speed})]}),t.jsxs("div",{className:"flex justify-center space-x-8 mt-6 text-white",children:[t.jsxs("div",{className:"bg-gray-800 px-4 py-2 rounded border",children:[t.jsx("span",{className:"text-gray-400",children:"MACH:"}),t.jsx("span",{className:"text-cyan-400 ml-2 font-mono",children:e.mach.toFixed(3)})]}),t.jsxs("div",{className:"bg-gray-800 px-4 py-2 rounded border",children:[t.jsx("span",{className:"text-gray-400",children:"OAT:"}),t.jsxs("span",{className:"text-blue-300 ml-2 font-mono",children:[Math.round(e.total_air_temperature),"°C"]})]}),t.jsxs("div",{className:"bg-gray-800 px-4 py-2 rounded border",children:[t.jsx("span",{className:"text-gray-400",children:"GS:"}),t.jsxs("span",{className:"text-green-400 ml-2 font-mono",children:[Math.round(e.groundspeed)," KT"]})]})]})]})})}const ae=({flightData:e})=>t.jsx("div",{className:"min-h-screen bg-gray-800 p-6",children:t.jsxs("div",{className:"max-w-7xl mx-auto",children:[t.jsx("div",{className:"mb-6 text-center",children:t.jsx("div",{className:"bg-gray-900 rounded-lg p-4 inline-block",children:t.jsxs("div",{className:"text-green-400 font-mono text-lg",children:[e.timestamp.toLocaleDateString()," - ",e.timestamp.toLocaleTimeString()]})})}),t.jsx(te,{flightData:e}),t.jsx(B,{flightData:e})]})}),D={DEFAULT_ZOOM:4,GOOGLE_MAPS_ZOOM:6,MAX_FLIGHT_PATH_POINTS:100,AIRCRAFT_MARKER_SCALE:1,FLIGHT_PATH_STROKE_WIDTH:4,SIMULATED_MAP_STROKE_WIDTH:3,UPDATE_TIMEOUT:5e3},re=[{name:"New York",position:{top:"25%",left:"33%"}},{name:"Chicago",position:{top:"50%",left:"25%"}},{name:"Dallas",position:{bottom:"33%",right:"25%"}},{name:"Denver",position:{top:"33%",left:"16%"}},{name:"Los Angeles",position:{bottom:"25%",left:"12%"}}],se=[{className:"absolute top-1/4 left-1/4 w-1/3 h-1/2 bg-green-800 opacity-40 rounded-full transform rotate-12"},{className:"absolute top-1/3 right-1/4 w-1/4 h-1/3 bg-green-700 opacity-30 rounded-lg"},{className:"absolute bottom-1/4 left-1/3 w-1/2 h-1/4 bg-green-800 opacity-35 rounded-full"}],ne=[{elementType:"geometry",stylers:[{color:"#1d2c4d"}]},{elementType:"labels.text.fill",stylers:[{color:"#8ec3b9"}]},{elementType:"labels.text.stroke",stylers:[{color:"#1a3646"}]},{featureType:"administrative.country",elementType:"geometry.stroke",stylers:[{color:"#4b6878"}]},{featureType:"water",elementType:"geometry",stylers:[{color:"#0e1626"}]},{featureType:"landscape.natural",elementType:"geometry",stylers:[{color:"#023e58"}]}],k={latLngToScreen:(e,r,n,o,a,l)=>{const s=n.lat,i=n.lng,c=Math.pow(2,o)/360,h=a/2+(r-i)*c*a/360,f=l/2-(e-s)*c*l/180;return{x:h,y:f}},generateFlightPathSVG:(e,r,n,o,a)=>e.length<2?"":e.map((s,i)=>{const{x:c,y:h}=k.latLngToScreen(s.lat,s.lng,r,n,o,a);return i===0?`M ${c} ${h}`:`L ${c} ${h}`}).join(" ")},oe=({flightData:e,width:r=800,height:n=600,apiKey:o})=>{const[a,l]=b.useState([]),[s,i]=b.useState({lat:40.7128,lng:-74.006}),[c,h]=b.useState(D.DEFAULT_ZOOM),[f,m]=b.useState(!1),[p,w]=b.useState(null),[y,x]=b.useState(!1),F=b.useRef(null),_=b.useRef(null),A=b.useRef(null),$=b.useRef(null);b.useEffect(()=>{if(!o||o==="YOUR_GOOGLE_MAPS_API_KEY"){x(!0),m(!0);return}if(window.google&&window.google.maps){m(!0),x(!1);return}if(document.querySelector('script[src*="maps.googleapis.com"]')){const N=setInterval(()=>{window.google&&window.google.maps&&(clearInterval(N),m(!0),x(!1))},100);setTimeout(()=>{clearInterval(N),(!window.google||!window.google.maps)&&(w("Google Maps failed to load"),x(!0),m(!0))},1e4);return}const u=document.createElement("script");return u.src=`https://maps.googleapis.com/maps/api/js?key=${o}&libraries=geometry`,u.async=!0,u.defer=!0,u.onload=()=>{window.google&&window.google.maps?(m(!0),x(!1),w(null)):(w("Google Maps API failed to initialize"),x(!0),m(!0))},u.onerror=()=>{w("Failed to load Google Maps script"),x(!0),m(!0)},window.gm_authFailure=()=>{w("Google Maps authentication failed"),x(!0),m(!0)},document.head.appendChild(u),()=>{window.gm_authFailure&&delete window.gm_authFailure}},[o]),b.useEffect(()=>{if(!(!f||y||!F.current||_.current)){if(!window.google||!window.google.maps){w("Google Maps not available"),x(!0);return}try{const g=new window.google.maps.Map(F.current,{center:{lat:e.latitude||40.7128,lng:e.longitude||-74.006},zoom:D.GOOGLE_MAPS_ZOOM,mapTypeId:window.google.maps.MapTypeId.TERRAIN,styles:ne});_.current=g;const u={path:"M 0,-18 L -6,-6 L -18,-4 L -18,0 L -6,2 L -3,10 L -6,12 L -3,14 L 0,12 L 4,14 L 6,12 L 3,10 L 6,2 L 18,0 L 18,-4 L 6,-6 Z",fillColor:"#fbbf24",fillOpacity:1,strokeColor:"#f59e0b",strokeWeight:1,scale:1,rotation:e.true_track_angle||0,anchor:new window.google.maps.Point(0,0)};A.current=new window.google.maps.Marker({position:{lat:e.latitude,lng:e.longitude},map:g,icon:u,title:`Altitude: ${Math.round(e.altitude)} ft, Speed: ${Math.round(e.groundspeed)} mph`}),$.current=new window.google.maps.Polyline({path:[],geodesic:!0,strokeColor:"#10b981",strokeOpacity:1,strokeWeight:3,map:g})}catch(g){console.error("Failed to initialize Google Maps:",g),w("Failed to initialize Google Maps"),x(!0)}}},[f,y,e.latitude,e.longitude]);const W=g=>{if(!(!_.current||!A.current||!$.current||y))try{const u={path:"M 0,-18 L -6,-6 L -18,-4 L -18,0 L -6,2 L -3,10 L -6,12 L -3,14 L 0,12 L 4,14 L 6,12 L 3,10 L 6,2 L 18,0 L 18,-4 L 6,-6 Z",fillColor:"#fbbf24",fillOpacity:1,strokeColor:"#f59e0b",strokeWeight:1,scale:1,rotation:e.true_track_angle||0,anchor:new window.google.maps.Point(0,0)};A.current.setPosition({lat:e.latitude,lng:e.longitude}),A.current.setIcon(u),A.current.setTitle(`Altitude: ${Math.round(e.altitude)} ft, Speed: ${Math.round(e.groundspeed)} mph`);const N=g.map(P=>({lat:P.lat,lng:P.lng}));$.current.setPath(N),_.current.setCenter({lat:e.latitude,lng:e.longitude})}catch(u){console.warn("Google Maps update failed:",u)}};b.useEffect(()=>{const g={lat:e.latitude,lng:e.longitude,timestamp:e.timestamp,altitude:e.altitude,speed:e.groundspeed};l(u=>{const N=[...u.slice(-99),g];return!y&&f&&W(N),N}),y&&i({lat:e.latitude,lng:e.longitude})},[e.latitude,e.longitude,e.timestamp,e.altitude,e.groundspeed,y,f]);const Z=()=>{y?h(g=>Math.min(10,g+1)):_.current&&_.current.setZoom(_.current.getZoom()+1)},E=()=>{y?h(g=>Math.max(1,g-1)):_.current&&_.current.setZoom(_.current.getZoom()-1)},V=()=>{y?i({lat:e.latitude,lng:e.longitude}):_.current&&_.current.setCenter({lat:e.latitude,lng:e.longitude})};return t.jsxs("div",{className:"bg-gray-900 rounded-xl p-4 shadow-2xl",children:[t.jsxs("div",{className:"mb-4",children:[t.jsx("h2",{className:"text-white text-xl font-bold mb-2",children:"Flight Tracking"}),t.jsxs("div",{className:"flex space-x-4 text-sm",children:[t.jsxs("div",{className:"text-gray-400",children:["Position:"," ",t.jsxs("span",{className:"text-cyan-400",children:[e.latitude.toFixed(4),"°,"," ",e.longitude.toFixed(4),"°"]})]}),t.jsxs("div",{className:"text-gray-400",children:["Track:"," ",t.jsxs("span",{className:"text-green-400",children:[Math.round(e.true_track_angle),"°"]})]})]})]}),t.jsxs("div",{className:"relative rounded-lg overflow-hidden",style:{width:r,height:n},children:[!f&&t.jsx("div",{className:"absolute inset-0 bg-gray-800 flex items-center justify-center",children:t.jsx("div",{className:"text-white",children:"Loading map..."})}),p&&t.jsxs("div",{className:"absolute top-2 left-2 bg-yellow-600 text-white px-2 py-1 rounded text-xs z-10",children:[p," - Using simulated map"]}),y?t.jsxs("div",{className:"relative bg-blue-950 rounded-lg overflow-hidden",style:{width:r,height:n},children:[t.jsx("div",{className:"absolute inset-0 bg-gradient-to-b from-blue-900 to-blue-950",children:se.map((g,u)=>t.jsx("div",{className:g.className},u))}),t.jsxs("svg",{className:"absolute inset-0",width:r,height:n,children:[t.jsx("defs",{children:t.jsx("pattern",{id:"grid",width:"50",height:"50",patternUnits:"userSpaceOnUse",children:t.jsx("path",{d:"M 50 0 L 0 0 0 50",fill:"none",stroke:"rgba(255,255,255,0.1)",strokeWidth:"1"})})}),t.jsx("rect",{width:r,height:n,fill:"url(#grid)"})]}),t.jsx("div",{className:"absolute inset-0 text-white text-xs",children:re.map((g,u)=>t.jsxs("div",{className:"absolute flex items-center",style:g.position,children:[t.jsx("div",{className:"w-2 h-2 bg-yellow-400 rounded-full mr-1"}),t.jsx("span",{children:g.name})]},u))}),t.jsxs("svg",{className:"absolute inset-0",width:r,height:n,children:[a.length>1&&t.jsx("path",{d:k.generateFlightPathSVG(a,s,c,r,n),fill:"none",stroke:"#10b981",strokeWidth:"3",strokeDasharray:"6,3",opacity:"1.0"}),a.slice(0,-1).map((g,u)=>{const{x:N,y:P}=k.latLngToScreen(g.lat,g.lng,s,c,r,n),G=Math.max(.3,(u+1)/a.length),ee=Math.max(1.5,3*((u+1)/a.length));return t.jsx("circle",{cx:N,cy:P,r:ee,fill:"#10b981",opacity:G,stroke:"#059669",strokeWidth:"0.5"},u)}),a.length>0&&t.jsx("g",{transform:`translate(${k.latLngToScreen(e.latitude,e.longitude,s,c,r,n).x}, ${k.latLngToScreen(e.latitude,e.longitude,s,c,r,n).y}) rotate(${e.true_track_angle})`,children:t.jsx("path",{d:"M 0,-18 L -6,-6 L -18,-4 L -18,0 L -6,2 L -3,10 L -6,12 L -3,14 L 0,12 L 4,14 L 6,12 L 3,10 L 6,2 L 18,0 L 18,-4 L 6,-6 Z",fill:"#fbbf24",stroke:"#f59e0b",strokeWidth:"1"})})]})]}):t.jsx("div",{ref:F,className:"w-full h-full",style:{width:r,height:n}}),t.jsxs("div",{className:"absolute top-4 right-4 flex flex-col space-y-2",children:[t.jsx("button",{onClick:Z,className:"bg-gray-700 hover:bg-gray-600 text-white p-2 rounded text-xs transition-colors",title:"Zoom In",children:"+"}),t.jsx("button",{onClick:E,className:"bg-gray-700 hover:bg-gray-600 text-white p-2 rounded text-xs transition-colors",title:"Zoom Out",children:"-"}),t.jsx("button",{onClick:V,className:"bg-gray-700 hover:bg-gray-600 text-white p-2 rounded text-xs transition-colors",title:"Center on Aircraft",children:"📍"})]})]}),t.jsxs("div",{className:"mt-4 grid grid-cols-2 md:grid-cols-4 gap-4 text-sm",children:[t.jsxs("div",{className:"bg-gray-800 p-3 rounded border",children:[t.jsx("div",{className:"text-gray-400 text-xs",children:"Ground Speed"}),t.jsxs("div",{className:"text-green-400 font-mono text-lg",children:[Math.round(e.groundspeed)," mph"]})]}),t.jsxs("div",{className:"bg-gray-800 p-3 rounded border",children:[t.jsx("div",{className:"text-gray-400 text-xs",children:"True Airspeed"}),t.jsxs("div",{className:"text-cyan-400 font-mono text-lg",children:[Math.round(e.airspeed)," mph"]})]}),t.jsxs("div",{className:"bg-gray-800 p-3 rounded border",children:[t.jsx("div",{className:"text-gray-400 text-xs",children:"Altitude"}),t.jsxs("div",{className:"text-blue-300 font-mono text-lg",children:[Math.round(e.altitude).toLocaleString()," ft"]})]}),t.jsxs("div",{className:"bg-gray-800 p-3 rounded border",children:[t.jsx("div",{className:"text-gray-400 text-xs",children:"To Arrival"}),t.jsx("div",{className:"text-white font-mono text-lg",children:"5:18"})]})]})]})},R=e=>{const[r,n]=b.useState(e||j);return b.useEffect(()=>{const o=setInterval(()=>{n(a=>{const l=new Date;let s=a.flight_phase;a.altitude<1e3?a.groundspeed<50?s="GROUND":a.vertical_speed>500?s="TAKEOFF":a.vertical_speed<-500?s="LANDING":s="APPROACH":a.altitude<1e4?a.vertical_speed>1e3?s="CLIMB":a.vertical_speed<-1e3?s="DESCENT":s="CRUISE":a.altitude>3e4?a.vertical_speed>500?s="CLIMB":a.vertical_speed<-500?s="DESCENT":s="CRUISE":a.vertical_speed>800?s="CLIMB":a.vertical_speed<-800?s="DESCENT":s="CRUISE";const i=a.airspeed/(661.5*Math.sqrt(288.15/(a.static_air_temperature+273.15))),h=(E=>{switch(E){case"TAKEOFF":return{altitudeRate:2500,speedChange:15,powerSetting:.95,stabilityFactor:.3};case"CLIMB":return{altitudeRate:1500,speedChange:5,powerSetting:.82,stabilityFactor:.7};case"CRUISE":return{altitudeRate:25,speedChange:1.5,powerSetting:.78,stabilityFactor:.95};case"DESCENT":return{altitudeRate:-1e3,speedChange:4,powerSetting:.45,stabilityFactor:.8};case"APPROACH":return{altitudeRate:-600,speedChange:6,powerSetting:.55,stabilityFactor:.6};case"LANDING":return{altitudeRate:-200,speedChange:8,powerSetting:.35,stabilityFactor:.4};default:return{altitudeRate:0,speedChange:1,powerSetting:.25,stabilityFactor:.9}}})(s),f=s==="CRUISE"?.3:1,m=(Math.random()-.5)*1.5*f,p=(Math.random()-.5)*.5,y=(h.powerSetting*100-a.n1_rpm)*.02+(Math.random()-.5)*.3*f,x=Math.max(20,Math.min(100,a.n1_rpm+y)),F=Math.max(30,Math.min(105,x*1.18+(Math.random()-.5)*.8)),_=300+x/100*350-a.altitude/1e3*6,A=Math.max(200,Math.min(950,_+(Math.random()-.5)*8)),$=Math.max(.6,1-a.altitude/12e4),W=x/100*2200*$,Z=Math.max(300,W+(Math.random()-.5)*40);return{airspeed:Math.max(0,Math.min(400,a.airspeed+(Math.random()-.5)*h.speedChange)),altitude:Math.max(0,a.altitude+a.vertical_speed/60+(Math.random()-.5)*20),groundspeed:Math.max(0,a.airspeed+a.wind_speed*Math.cos((a.wind_direction-a.true_heading)*Math.PI/180)),mach:Math.max(0,Math.min(.95,i+(Math.random()-.5)*.01)),pitch_angle:Math.max(-20,Math.min(25,a.pitch_angle+a.pitch_rate*.02+(Math.random()-.5)*.5)),roll_angle:Math.max(-45,Math.min(45,a.roll_angle+a.roll_rate*.02+(Math.random()-.5)*.8)),true_heading:(()=>{const g=(-123.1207-a.longitude)*Math.PI/180,u=a.latitude*Math.PI/180,N=49.2827*Math.PI/180,P=Math.sin(g)*Math.cos(N),G=Math.cos(u)*Math.sin(N)-Math.sin(u)*Math.cos(N)*Math.cos(g);let H=(Math.atan2(P,G)*180/Math.PI+360)%360-a.true_heading;H>180&&(H-=360),H<-180&&(H+=360);const be=Math.max(-1,Math.min(1,H*.1));return(a.true_heading+be+a.true_heading_rate*.02+(Math.random()-.5)*.2+360)%360})(),magnetic_heading:(a.true_heading-12+360)%360,pitch_rate:Math.max(-10,Math.min(10,(Math.random()-.5)*2)),roll_rate:Math.max(-15,Math.min(15,(Math.random()-.5)*3)),true_heading_rate:Math.max(-5,Math.min(5,(Math.random()-.5)*1)),vertical_speed:Math.max(-4e3,Math.min(4e3,h.altitudeRate+(Math.random()-.5)*300)),true_track_angle:(a.true_heading+(Math.random()-.5)*2+360)%360,body_lateral_accel:Math.max(-2,Math.min(2,a.roll_angle*.02+(Math.random()-.5)*.1)),body_long_accel:Math.max(-1,Math.min(1,(x-a.n1_rpm)*.01+(Math.random()-.5)*.05)),body_normal_accel:Math.max(-1,Math.min(3,1+a.pitch_angle*.015+(Math.random()-.5)*.08)),latitude:(()=>{const E=a.true_track_angle*Math.PI/180;return a.latitude+a.groundspeed*Math.cos(E)/364e3})(),longitude:(()=>{const E=a.true_track_angle*Math.PI/180;return a.longitude+a.groundspeed*Math.sin(E)/(364e3*Math.cos(a.latitude*Math.PI/180))})(),total_air_temperature:Math.max(-70,Math.min(50,15-a.altitude/1e3*2+p)),static_air_temperature:Math.max(-70,Math.min(50,15-a.altitude/1e3*2+p-2)),wind_speed:Math.max(0,Math.min(150,a.wind_speed+m)),wind_direction:(a.wind_direction+(Math.random()-.5)*2+360)%360,static_pressure:Math.max(100,1013.25*Math.pow(1-.0065*a.altitude/288.15,5.255)),n1_rpm:x,n2_rpm:F,egt:A,fuel_flow:Z,oil_pressure:Math.max(20,Math.min(100,45+x/100*35+(Math.random()-.5)*3)),oil_temperature:Math.max(-40,Math.min(150,60+x/100*40+(Math.random()-.5)*5)),flap_position:s==="TAKEOFF"||s==="APPROACH"||s==="LANDING"?Math.max(0,Math.min(40,20+(Math.random()-.5)*3)):0,gear_position:a.altitude<2500&&(s==="TAKEOFF"||s==="APPROACH"||s==="LANDING"||s==="GROUND"),cabin_altitude:Math.min(8e3,Math.max(0,a.altitude*.2+6e3+(Math.random()-.5)*50)),cabin_pressure_diff:Math.max(0,Math.min(9.5,(a.altitude-6e3)/5e3*8+(Math.random()-.5)*.05)),ils_deviation:s==="APPROACH"?(Math.random()-.5)*1.5:0,glideslope_deviation:s==="APPROACH"?(Math.random()-.5)*1.2:0,dme_distance:(()=>{const V=-123.1207,g=3440.065,u=(49.2827-a.latitude)*Math.PI/180,N=(V-a.longitude)*Math.PI/180,P=Math.sin(u/2)*Math.sin(u/2)+Math.cos(a.latitude*Math.PI/180)*Math.cos(49.2827*Math.PI/180)*Math.sin(N/2)*Math.sin(N/2),G=2*Math.atan2(Math.sqrt(P),Math.sqrt(1-P));return Math.max(0,g*G)})(),date:l.toLocaleDateString("en-GB"),time:l.toTimeString().split(" ")[0],timestamp:l,flight_phase:s}})},2e3);return()=>clearInterval(o)},[]),r},j={airspeed:285,altitude:35e3,groundspeed:465,mach:.82,pitch_angle:2.5,roll_angle:-1.2,true_heading:285,magnetic_heading:277,pitch_rate:.1,roll_rate:-.2,true_heading_rate:.05,vertical_speed:50,true_track_angle:287,body_lateral_accel:-.02,body_long_accel:.01,body_normal_accel:1.01,latitude:43.6532,longitude:-79.3832,total_air_temperature:-54,static_air_temperature:-56,wind_speed:45,wind_direction:285,static_pressure:238,n1_rpm:78.5,n2_rpm:94.2,egt:485,fuel_flow:1650,oil_pressure:62,oil_temperature:88,flap_position:0,gear_position:!1,cabin_altitude:6800,cabin_pressure_diff:8.1,ils_deviation:0,glideslope_deviation:0,dme_distance:2200,date:new Date().toLocaleDateString("en-GB"),time:new Date().toTimeString().split(" ")[0],timestamp:new Date,flight_phase:"CRUISE"};function z(e){return{altitude:I(e.altitude,1,M.ALTITUDE),airspeed:I(e.airspeed,128,M.AIRSPEED),mach:I(e.mach,8192,M.MACH),heading:I(e.true_heading,182.0444,M.HEADING),vertical_speed:I(e.vertical_speed,32,M.VERTICAL_SPEED),pitch:I(e.pitch_angle,4096,M.PITCH),roll:I(e.roll_angle,4096,M.ROLL),temperature:I(e.static_air_temperature,256,M.TEMPERATURE)}}function le(e){const r=(n,o)=>n.data/o;return{altitude:e.altitude?r(e.altitude,1):void 0,airspeed:e.airspeed?r(e.airspeed,128):void 0,mach:e.mach?r(e.mach,8192):void 0,true_heading:e.heading?r(e.heading,182.0444):void 0,vertical_speed:e.vertical_speed?r(e.vertical_speed,32):void 0,pitch_angle:e.pitch?r(e.pitch,4096):void 0,roll_angle:e.roll?r(e.roll,4096):void 0,static_air_temperature:e.temperature?r(e.temperature,256):void 0}}const ie=e=>{const[r,n]=b.useState(()=>z(e||j)),o=R(e);return b.useEffect(()=>{const a=setInterval(()=>{n(z(o))},2e3);return()=>clearInterval(a)},[o]),{rawData:r,flightData:o}};class U{constructor(r,n,o,a){v(this,"label");v(this,"sdi");v(this,"data");v(this,"ssm");v(this,"parity");this.label=r,this.sdi=n,this.data=o,this.ssm=a,this.parity=this.calculateParity()}calculateParity(){const r=this.label<<24|this.sdi<<22|this.data<<3|this.ssm<<1;let n=0;for(let o=0;o<31;o++)r&1<<o&&n++;return n%2===0?1:0}toInt32(){return this.label<<24|this.sdi<<22|this.data<<3|this.ssm<<1|this.parity}static fromInt32(r){const n=r>>24&255,o=r>>22&3,a=r>>3&524287,l=r>>1&3;return new U(n,o,a,l)}}const T={ALTITUDE:131,AIRSPEED:134,MACH:135,HEADING:146,VERTICAL_SPEED:245,PITCH:212,ROLL:213,TEMPERATURE:137},de={NORMAL_OPERATION:3};function C(e,r=1,n,o=0){const a=Math.round(e*r)&524287;return new U(n,o,a,de.NORMAL_OPERATION)}function O(e,r){return e.data/r}function ce(e){const r={};return e.altitude!==void 0&&(r.altitude=C(e.altitude,1,T.ALTITUDE)),e.airspeed!==void 0&&(r.airspeed=C(e.airspeed,128,T.AIRSPEED)),e.mach!==void 0&&(r.mach=C(e.mach,8192,T.MACH)),e.heading!==void 0&&(r.heading=C(e.heading,182.0444,T.HEADING)),e.vertical_speed!==void 0&&(r.vertical_speed=C(e.vertical_speed,32,T.VERTICAL_SPEED)),e.pitch_angle!==void 0&&(r.pitch=C(e.pitch_angle,4096,T.PITCH)),e.roll_angle!==void 0&&(r.roll=C(e.roll_angle,4096,T.ROLL)),e.temperature!==void 0&&(r.temperature=C(e.temperature,256,T.TEMPERATURE)),r}function he(e){const r={};return e.altitude&&(r.altitude=O(e.altitude,1)),e.airspeed&&(r.airspeed=O(e.airspeed,128)),e.mach&&(r.mach=O(e.mach,8192)),e.heading&&(r.heading=O(e.heading,182.0444)),e.vertical_speed&&(r.vertical_speed=O(e.vertical_speed,32)),e.pitch&&(r.pitch_angle=O(e.pitch,4096)),e.roll&&(r.roll_angle=O(e.roll,4096)),e.temperature&&(r.temperature=O(e.temperature,256)),r}function ue(e){return Object.values(e).map(r=>r.toInt32())}function ge(e,r){const n={};return e.forEach((o,a)=>{r[a]&&(n[r[a]]=U.fromInt32(o))}),n}function me(e){return e.calculateParity()===e.parity}function pe(e){const r=Object.entries(T).find(([,n])=>n===e);return r?r[0]:void 0}d.ARINC429DataBus=B,d.ARINC429Word=L,d.ARINC429_LABELS=M,d.AircraftPFD=ae,d.AirspeedIndicator=q,d.AltitudeIndicator=X,d.AttitudeIndicator=Y,d.FlightTracking=oe,d.HeadingIndicator=J,d.SSM=S,d.VerticalSpeedIndicator=Q,d.convertA429ToFlightParams=he,d.convertFlightParamsToA429=ce,d.convertFromA429RawData=le,d.convertToA429RawData=z,d.defaultFlightData=j,d.encodeA429Value=I,d.getLabelName=pe,d.rawDataToWords=ue,d.useA429RawDataSimulator=ie,d.useA429ValuesSimulator=R,d.validateA429Word=me,d.wordsToRawData=ge,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});