1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4186],{10880:(e,t,r)=>{"use strict";r.d(t,{rT:()=>s});let s=e=>{switch(e){case"kph":return"km/h";case"mph":return"mph";default:return e}}},38534:(e,t,r)=>{"use strict";r.r(t),r.d(t,{__N_SSP:()=>eS,default:()=>eL});var s=r(37876),a=r(62875),i=r(89099),n=r(14232),l=r(75656),o=r(49915),d=r(85392),c=r(74),p=r(93408),u=r(56785),m=r(49086),h=r(27318),g=r(73865);let x=({tripDelay:e,tripStatus:t})=>{let r,a,i,n,l,{t:o}=(0,g.B)();if(!t||"scheduled"===t)return null;let d=null!==e?Math.round(e/60):null,c=null!==d&&d>0,p=null!==d&&d<0;if(c)r=1===d?o("delayBehindSingular"):o("delayBehindPlural").replace("{n}",d),a="text-red-700",i="bg-red-50",n="border-red-200",l="text-red-500";else if(p){let e=Math.abs(d);r=1===e?o("delayAheadSingular"):o("delayAheadPlural").replace("{n}",e),a="text-green-700",i="bg-green-50",n="border-green-200",l="text-green-500"}else r=o("delayOnTime"),a="text-green-700",i="bg-green-50",n="border-green-200",l="text-green-500";return(0,s.jsxs)("div",{className:`overflow-visible rounded-lg ${i} border ${n} px-4 py-5 shadow sm:p-6`,children:[(0,s.jsx)("dt",{className:"truncate text-sm font-medium text-gray-500",children:o("delayCardTitle")}),(0,s.jsx)("dd",{className:"mt-1",children:(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(h.A,{className:`h-6 w-6 ${l} flex-shrink-0`}),(0,s.jsx)("span",{className:`text-lg font-semibold ${a}`,children:r})]})})]})};var f=r(95906),y=r(48166),v=r(10880);let w=({currentSpeed:e,maxSpeed:t})=>{let r=(0,n.useMemo)(()=>Array.from({length:20},(e,t)=>{let r=-210+240*t/19,s=t%4==0?8:4,a=50+25*Math.cos(r*Math.PI/180),i=50+25*Math.sin(r*Math.PI/180);return{x1:a,y1:i,x2:50+(25-s)*Math.cos(r*Math.PI/180),y2:50+(25-s)*Math.sin(r*Math.PI/180)}}),[]),a=(0,n.useMemo)(()=>t?-210+240*Math.min(e/t,1):-210+e/100*240,[e,t]);if(null==e)return null;let i=t?Math.round(e/t*100):e;return(0,s.jsxs)("svg",{viewBox:"0 0 100 100",className:"w-full h-full",children:[(0,s.jsx)("circle",{cx:"50",cy:"50",r:"30",fill:"none",stroke:"#000000",strokeWidth:"2"}),r.map((e,t)=>(0,s.jsx)("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:"#000000",strokeWidth:"1"},t)),(0,s.jsx)("line",{x1:"50",y1:"50",x2:50+20*Math.cos(a*Math.PI/180),y2:50+20*Math.sin(a*Math.PI/180),stroke:"#000000",strokeWidth:"2",strokeLinecap:"round"}),(0,s.jsx)("circle",{cx:"50",cy:"50",r:"2",fill:"#000000"}),(0,s.jsxs)("text",{x:"50",y:"70",textAnchor:"middle",fontSize:"11",fill:"#9e9e9e",children:[i,t?"%":""]})]})},j=({train:e,speedLimit:t=null})=>{let[r,a]=(0,n.useState)(!1),{units:i,convertSpeed:l,formatSpeed:o}=(0,y.t)(),{t:d}=(0,g.B)(),c=t&&!t.error?{...t,value:l(t.value,"kph",i)}:t,p=null==t?d("speedLimitLoading"):t?.error?d("NO_RAILWAY_FOUND"===t.error||"NO_SPEED_LIMIT"===t.error?"speedLimitNoData":"API_ERROR"===t.error?"speedLimitError":"speedLimitUnavailable"):d("speedLimitTrack").replace("{value}",o(c.value,(0,v.rT)(i)));return(0,s.jsxs)("div",{className:"overflow-visible rounded-lg bg-white px-4 py-5 shadow shadow-lg sm:p-6 relative",children:[(0,s.jsx)("dt",{className:"truncate text-sm font-medium text-gray-500",children:d("speedCardTitle")}),(0,s.jsxs)("dd",{className:"mt-1 text-3xl font-semibold tracking-tight text-gray-900",children:[e?.normalized?.speed?.has_speed?o(l(e.normalized.speed.value,e.normalized.speed.unit,i),(0,v.rT)(i)):(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{children:d("speedCardNA")}),(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(f.A,{className:"h-5 w-5 text-gray-400 cursor-pointer",onClick:()=>a(!r)}),r&&(0,s.jsx)("div",{className:"absolute z-50 w-64 px-4 py-2 text-sm text-gray-600 bg-white border rounded shadow-lg left-6 top-0",children:d("speedCardNoReporting")})]})]}),e?.normalized?.speed?.has_speed&&e?.normalized?.speed?.value===0&&(0,s.jsx)("div",{className:"text-sm text-red-500 font-normal",children:d("speedCardStopped")}),(0,s.jsx)("div",{className:"text-sm text-gray-500 font-normal mt-2",children:p}),e?.normalized?.speed?.has_speed&&(0,s.jsx)("div",{className:"absolute right-4 top-1/2 -translate-y-1/2 w-24 h-24",children:(0,s.jsx)(w,{currentSpeed:l(e.normalized.speed.value,e.normalized.speed.unit,i),maxSpeed:c?.value})})]})]})},b=({train:e,stopProgress:t})=>{let{t:r}=(0,g.B)();if(!e)return(0,s.jsx)("div",{className:"overflow-hidden rounded-lg bg-white px-4 py-5 shadow shadow-lg sm:p-6",children:(0,s.jsxs)("div",{className:"animate-pulse",children:[(0,s.jsx)("div",{className:"h-4 bg-gray-200 rounded w-3/4 mb-4"}),(0,s.jsx)("div",{className:"h-4 bg-gray-200 rounded w-1/2"})]})});if(!t&&e.gtfs?.trip_id)return(0,s.jsxs)("div",{className:"overflow-hidden rounded-lg bg-white px-4 py-5 shadow shadow-lg sm:p-6",children:[(0,s.jsx)("dt",{className:"truncate text-sm font-medium text-gray-500",children:r("statusCardStatus")}),(0,s.jsx)("dd",{className:"mt-1",children:(0,s.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,s.jsxs)("svg",{className:"animate-spin h-5 w-5 text-gray-400",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[(0,s.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,s.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),(0,s.jsx)("span",{className:"text-gray-500",children:r("statusCardLoading")})]})})]});if(!e.gtfs?.trip_id)return(0,s.jsxs)("div",{className:"overflow-hidden rounded-lg bg-white px-4 py-5 shadow shadow-lg sm:p-6",children:[(0,s.jsx)("dt",{className:"truncate text-sm font-medium text-gray-500",children:r("statusCardStatus")}),(0,s.jsxs)("dd",{className:"mt-1 text-3xl font-semibold tracking-tight text-gray-900",children:[(0,s.jsx)("span",{children:r("statusCardUnknown")}),(0,s.jsx)("div",{className:"text-xs text-gray-500 font-normal mt-2",children:r("statusCardNoSchedule")})]})]});let a=t?.trainIsAtStop,i=t?.nextStops?.[0],n=t?.progressBetweenStops,l=n?.percent>=.84,o=r("statusCardStatus");return a?o=r("statusCardStoppedAt"):i&&(o=r(l?"statusCardArrivingAt":"statusCardEnRouteTo")),(0,s.jsxs)("div",{className:"overflow-hidden rounded-lg bg-white px-4 py-5 shadow shadow-lg sm:p-6",children:[(0,s.jsx)("dt",{className:"truncate text-sm font-medium text-gray-500",children:o}),(0,s.jsxs)("dd",{className:"mt-1 text-3xl font-semibold tracking-tight text-gray-900",children:[a?(0,s.jsx)("span",{children:a.stop_name}):i?(0,s.jsx)("span",{children:i.stop_name}):(0,s.jsx)("span",{children:r("statusCardUnknown")}),i&&!a&&n&&(0,s.jsxs)("div",{className:"text-xs text-gray-500 font-normal mt-2",children:[r("statusCardProgress").replace("{pct}",Math.round(100*n.percent))," ",(0,s.jsx)("span",{children:r("statusCardDistance").replace("{dist}",n.distance.toFixed(1)).replace("{total}",n.totalDistance.toFixed(1))})]})]})]})};var N=r(13061),_=r(81047),k=r(31134);let S=()=>(0,s.jsx)("div",{className:"inline-block bg-yellow-50 text-yellow-700 p-3 rounded-lg shadow-sm text-sm mb-4",role:"alert",children:(0,s.jsxs)("div",{className:"flex",children:[(0,s.jsx)("div",{className:"flex items-center mr-3",children:(0,s.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-6 w-6 flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"font-medium mb-0 text-yellow-700 text-sm",children:"Inferred Speed Data"}),(0,s.jsx)("p",{className:"mt-0 text-xs",children:"This transit network does not provide speed data directly. We have inferred it from timestamps and GPS co
1ordinates."})]})]})});_.t1.register(_.PP,_.kc,_.FN,_.No,_.hE,_.m_,_.s$);let L=({trainPositions:e})=>{let[t,r]=(0,n.useState)({labels:[],datasets:[]}),[a,i]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{if(e&&Array.isArray(e)&&e.length>0){let t=[...e].sort((e,t)=>new Date(e.updated)-new Date(t.updated)),s=!1,a=t.map((e,r)=>{if(e.normalized?.speed?.has_speed)return e.normalized.speed.kph;if(r>0){let a=t[r-1],i=N.I([a.lng,a.lat],[e.lng,e.lat],{units:"kilometers"}),n=(new Date(e.updated)-new Date(a.updated))/36e5;return s=!0,n>0?Math.round(i/n):0}return 0});i(s),r({labels:t.map(e=>new Date(e.updated).toLocaleString()),datasets:[{label:"Speed",data:a,borderColor:"rgb(99, 102, 241)",backgroundColor:"rgba(99, 102, 241, 0.5)",tension:.4,fill:!1}]})}},[e]),(0,s.jsxs)("div",{className:"bg-white mt-2 rounded-lg",children:[(0,s.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,s.jsxs)("div",{children:[(0,s.jsx)("h5",{className:"text-xl font-bold text-gray-800",children:"Previous Speeds"}),(0,s.jsx)("p",{className:"text-base text-gray-600",children:"This train's speed over the last 30 minutes in km/hour"})]})}),(0,s.jsx)("div",{className:"h-64",children:e?.length>0?(0,s.jsxs)(s.Fragment,{children:[a&&(0,s.jsx)(S,{}),(0,s.jsx)(k.N1,{options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!0,position:"top",labels:{color:"rgba(0, 0, 0, 0.7)"}},tooltip:{mode:"index",intersect:!1,callbacks:{label:function(e){let t=e.dataset.label||"";return t&&(t+=": "),null!==e.parsed.y&&(t+=e.parsed.y+" kph"),t}}}},scales:{x:{display:!0,grid:{display:!0,drawBorder:!1,color:"rgba(0, 0, 0, 0.1)"},ticks:{color:"rgba(0, 0, 0, 0.7)",maxRotation:45,minRotation:45,callback:function(e){return new Date(this.getLabelForValue(e)).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}}},y:{display:!0,beginAtZero:!0,grid:{display:!1,drawBorder:!1},ticks:{color:"rgba(0, 0, 0, 0.7)"}}},elements:{point:{radius:2},line:{tension:.4}}},data:t})]}):(0,s.jsx)("p",{className:"text-gray-500 text-center pt-16",children:"Speed data not available for this train"})})]})},M=({train:e})=>(0,s.jsxs)("div",{className:"overflow-hidden rounded-lg bg-white px-4 py-5 shadow shadow-lg sm:p-6",children:[(0,s.jsx)("dt",{className:"truncate text-sm font-medium text-gray-500",children:"Destination"}),(0,s.jsx)("dd",{className:"mt-1 text-3xl font-semibold tracking-tight text-gray-900",children:e?.dst||"Unknown"})]}),I=({bearing:e})=>{let t=(0,n.useMemo)(()=>Array.from({length:32},(e,t)=>{let r=11.25*t,s=t%8==0?8:5,a=50+44*Math.cos(r*Math.PI/180),i=50+44*Math.sin(r*Math.PI/180);return{x1:a,y1:i,x2:50+(44-s)*Math.cos(r*Math.PI/180),y2:50+(44-s)*Math.sin(r*Math.PI/180)}}),[]);return null==e?null:(0,s.jsxs)("div",{className:"w-12 h-12 rounded-full flex items-center justify-center relative",style:{backgroundColor:"white",border:"2px solid black"},children:[(0,s.jsx)("svg",{viewBox:"0 0 100 100",className:"w-full h-full",children:t.map((e,t)=>(0,s.jsx)("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:"black",strokeWidth:"1.5"},t))}),(0,s.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"black",className:"w-6 h-6 absolute",style:{transform:`rotate(${e}deg)`},children:(0,s.jsx)("path",{fillRule:"evenodd",d:"M10 17a.75.75 0 01-.75-.75V5.612L5.29 9.77a.75.75 0 01-1.08-1.04l5.25-5.5a.75.75 0 011.08 0l5.25 5.5a.75.75 0 11-1.08 1.04l-3.96-4.158V16.25A.75.75 0 0110 17z",clipRule:"evenodd"})})]})},$=({train:e})=>(0,s.jsxs)("div",{className:"overflow-hidden rounded-lg bg-white px-4 py-5 shadow shadow-lg sm:p-6 relative",children:[(0,s.jsx)("dt",{className:"truncate text-sm font-medium text-gray-500",children:"Direction"}),(0,s.jsx)("dd",{className:"mt-1 text-3xl font-semibold tracking-tight text-gray-900",children:e?.dir?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{children:[["North","Northeast","East","Southeast","South","Southwest","West","Northwest"][Math.round(e.dir%360/45)%8],(0,s.jsxs)("div",{className:"text-sm text-gray-500 font-normal",children:["Bearing: ",e.dir,"\xb0"]})]}),(0,s.jsx)("div",{className:"absolute right-4 top-1/2 -translate-y-1/2",children:(0,s.jsx)(I,{bearing:e.dir})})]}):"Unknown"})]}),C=({train:e})=>
1{let[t,r]=(0,n.useState)(0);return(0,n.useEffect)(()=>{if(!e?.updated)return;let t=()=>Math.floor((Date.now()-new Date(e.updated).getTime())/1e3);r(t());let s=setInterval(()=>{r(t())},1e3);return()=>clearInterval(s)},[e?.updated]),(0,s.jsxs)("div",{className:"overflow-hidden rounded-lg bg-white px-4 py-5 shadow shadow-lg sm:p-6",children:[(0,s.jsx)("dt",{className:"truncate text-sm font-medium text-gray-500",children:"Position last synced from GPS"}),(0,s.jsx)("dd",{className:"mt-1 text-3xl font-semibold tracking-tight text-gray-900",children:e?.updated?(e=>{if(e<60)return`${e}s ago`;let t=Math.floor(e/60);return`${t}m ${e%60}s ago`})(t):"Unknown"})]})},A=({train:e})=>(0,s.jsxs)("div",{className:"overflow-hidden rounded-lg bg-white px-4 py-5 shadow shadow-lg sm:p-6",children:[(0,s.jsx)("dt",{className:"truncate text-sm font-medium text-gray-500",children:"Network"}),(0,s.jsx)("dd",{className:"mt-1 text-3xl font-semibold tracking-tight text-gray-900",children:(0,s.jsx)("div",{style:{borderBottom:`4px solid ${e?.normalized?.network?.color||"#000"}`,display:"inline-block"},children:e?.normalized?.network?.name||"Unknown"})})]}),T=({train:e})=>(0,s.jsxs)("div",{className:"overflow-hidden rounded-lg bg-white px-4 py-5 shadow shadow-lg sm:p-6",children:[(0,s.jsx)("dt",{className:"truncate text-sm font-medium text-gray-500",children:"Origin"}),(0,s.jsx)("dd",{className:"mt-1 text-3xl font-semibold tracking-tight text-gray-900",children:e?.org||"Unknown"})]});var P=r(66837);let D=({train:e})=>(0,s.jsxs)("div",{className:"overflow-hidden rounded-lg bg-white px-4 py-5 shadow shadow-lg sm:p-6 relative",children:[(0,s.jsx)("dt",{className:"truncate text-sm font-medium text-gray-500",children:"Vehicle Type"}),(0,s.jsxs)("dd",{className:"mt-1 text-3xl font-semibold tracking-tight text-gray-900",children:[(0,s.jsx)("span",{children:e?.normalized?.vehicle?.type?.name}),(0,s.jsx)("div",{className:"absolute right-4 top-1/2 -translate-y-1/2",children:(0,s.jsx)("div",{className:"w-14 h-14 rounded-full border-2 border-black flex items-center justify-center",children:(0,s.jsx)(P.A,{iconSlug:e?.normalized?.vehicle?.type?.icon,size:48,color:"#fff",textColor:"#000"})})})]})]}),z=({train:e,speedLimit:t,stopProgress:r})=>{let[a,i]=(0,n.useState)(0),{t:l}=(0,g.B)();(0,n.useEffect)(()=>{if(!e?.updated)return;let t=()=>Math.floor((Date.now()-new Date(e.updated).getTime())/1e3);i(t());let r=setInterval(()=>{i(t())},1e3);return()=>clearInterval(r)},[e?.updated]);let o=e?.updated?l("detailsPanelSecondsAgo").replace("{n}",a):l("detailsPanelUnknown");return(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsxs)("dl",{className:"grid grid-cols-2 gap-5 lg:grid-cols-4",children:[(0,s.jsx)(b,{train:e,stopProgress:r}),(0,s.jsx)(T,{train:e}),(0,s.jsx)(M,{train:e}),(0,s.jsx)(A,{train:e}),(0,s.jsx)(j,{train:e,speedLimit:t}),(0,s.jsx)($,{train:e}),(0,s.jsx)(D,{train:e}),(0,s.jsx)(C,{train:e})]}),(0,s.jsxs)("div",{className:"text-xs text-gray-500 mt-2 text-right",children:[l("detailsPanelLastUpdated")," ",o]})]})};var F=r(12519),E=r(18607),R=r(52104),B=r(47138),U=r(28168);r(4402);var O=r(59025),W=r(59531);let q=({historicalPositions:e,trip:t,initialCenter:r,initialZoom:a=10,height:i=300,train:l})=>{let o=(0,n.useRef)(null),d=(0,n.useRef)(null),c=(0,n.useRef)(!1),[p,u]=(0,n.use
1State)(!1),{units:m,convertSpeed:h,formatSpeed:g}=(0,y.t)(),x=r=>{if(!(!t?.shape_points||e?.length<2))try{let s={type:"Feature",geometry:{type:"LineString",coordinates:t.shape_points.map(e=>[e.shape_pt_lon,e.shape_pt_lat])}};r.getSource("trip-shape")?r.getSource("trip-shape").setData(s):r.addSource("trip-shape",{type:"geojson",data:s}),r.getLayer("trip-shape-layer")||r.addLayer({id:"trip-shape-layer",type:"line",source:"trip-shape",layout:{"line-join":"round","line-cap":"round"},paint:{"line-color":"#555555","line-width":3,"line-opacity":.7}});let a=[...e].sort((e,t)=>new Date(e.updated)-new Date(t.updated)),i=F.wi(t.shape_points.map(e=>[e.shape_pt_lon,e.shape_pt_lat])),n=F.zx([a[0].lng,a[0].lat]),o=F.zx([a[a.length-1].lng,a[a.length-1].lat]),d=E.n(n,o,i),c=R.B(d,{units:"kilometers"}),p=!1,m=a.map((e,t)=>{let r=F.zx([e.lng,e.lat]),s=B.W(d,r,{units:"kilometers"}).properties.location/c,i=e.normalized?.speed?.has_speed,n=i?e.normalized.speed.value:null;if(!i&&t>0){let s=a[t-1],i=N.I(r,F.zx([s.lng,s.lat]),{units:"kilometers"}),l=(new Date(e.updated)-new Date(s.updated))/36e5;n=l>0?Math.round(i/l):0,p=!0}let l="#ef4444";if(n>=100)l="#6366f1";else if(n>=80){let e=(n-80)/20;l=f("#3b82f6","#6366f1",e)}else if(n>=60){let e=(n-60)/20;l=f("#22c55e","#3b82f6",e)}else if(n>=40){let e=(n-40)/20;l=f("#eab308","#22c55e",e)}else if(n>=20){let e=(n-20)/20;l=f("#f97316","#eab308",e)}else if(n>=10){let e=(n-10)/10;l=f("#ef4444","#f97316",e)}return{percentage:s,color:l}}).sort((e,t)=>e.percentage-t.percentage).reduce((e,t,r,s)=>((0===r||t.percentage>s[r-1].percentage)&&e.push(t),e),[]).flatMap(({percentage:e,color:t})=>[e,t]);u(e=>!!p||e),r.getSource("speed-line")?r.getSource("speed-line").setData(d):r.addSource("speed-line",{type:"geojson",data:d,lineMetrics:!0}),r.getLayer("speed-line")||r.addLayer({id:"speed-line",type:"line",source:"speed-line",paint:{"line-width":4,"line-opacity":.8,"line-gradient":["interpolate",["linear"],["line-progress"],...m]}});let h={type:"FeatureCollection",features:e.slice(0,-1).map(e=>({type:"Feature",geometry:{type:"Point",coordinates:[e.lng,e.lat]},properties:{updated:e.updated,speed:e.normalized?.speed?.has_speed?`${Math.round(e.normalized.speed.value)} km/h`:""}}))};if(r.getSource("historical-positions")?r.getSource("historical-positions").setData(h):r.addSource("historical-positions",{type:"geojson",data:h}),e?.length>0){let t=e[0],s={type:"Feature",geometry:{type:"Point",coordinates:[t.lng,t.lat]}};r.getSource("historical-endpoint")?r.getSource("historical-endpoint").setData(s):r.addSource("historical-endpoint",{type:"geojson",data:s}),r.getLayer("historical-endpoint")||r.addLayer({id:"historical-endpoint",type:"circle",source:"historical-endpoint",paint:{"circle-radius":6,"circle-color":"#000000","circle-opacity":.8,"circle-stroke-width":2,"circle-stroke-color":"#ffffff"}}),r.on("click","historical-endpoint",e=>{let t=e.features[0].geometry.coordinates.slice();new U.A.Popup({closeButton:!1,closeOnClick:!0,className:"historical-endpoint-popup"}).setLngLat(t).setHTML(` 2 <div class="p-2"> 3 <h3 class="font-bold text-gray-900">Historical Data Limit</h3> 4 <p class="text-gray-600">We don't keep historical speed data past this point</p> 5 </div> 6 `).addTo(r)}),r.on("mouseenter","historical-endpoint",()=>{r.getCanvas().style.cursor="pointer"}),r.on("mouseleave","historical-endpoint",()=>{r.getCanvas().style.cursor=""})}if(t?.stop_times){let e={type:"FeatureCollection",features:t.stop_times.map(e=>({type:"Feature",geometry:{type:"Point",coordinates:[e.stop.stop_lon,e.stop.stop_lat]},properties:{name:e.stop.stop_name,arrival:e.arrival_time.split(":").slice(0,2).join(":"),departure:e.departure_time.split(":").slice(0,2).join(":")}}))};r.getSource("trip-stops")?r.getSource("trip-stops").setData(e):r.addSource("trip-stops",{type:"geojson",data:e}),r.getLayer("trip-stops")||r.addLayer({id:"trip-stops",type:"circle",source:"trip-stops",paint:{"circle-radius":5,"circle-color":"#333","circle-stroke-width":2,"circle-stroke-color":"#ffffff"}}),r.getLayer("trip-stop-labels")||r.addLayer({id:"trip-stop-labels",type:"symbol",source:"trip-stops",layout:{"text-field":["get","name"],"text-variable-anchor":["top","bottom","left","right"],"text-radial-offset":.8,"text-justify":"auto","text-size":12},paint:{"text-color":"#000000","text-halo-color":"#ffffff","text-halo-width":2}}),r.on("click","trip-stops",e=>{let t=e.features[0].geometry.coordinates.slice(),s=e.features[0].properties;new U.A.Popup({closeButton:!1,closeOnClick:!0,className:"stop-popup"}).setLngLat(t).setHTML(` 7 <div class="p-2"> 8 <h3 class="font-bold text-gray-900">${s.name}</h3> 9 <p class="text-gray-600">Scheduled Arrival: ${s.arrival}</p> 10 <p class="text-gray-600">Scheduled Departure: ${s.departure}</p> 11 </div> 12 `).addTo(r)}),r.on("mouseenter","trip-stops",()=>{r.getCanvas().style.cursor="pointer"}),r.on("mouseleave","trip-stops",()=>{r.getCanvas().style.cursor=""})}if(l){let e={type:"Feature",geometry:{type:"Point",coordinates:[l.lng,l.lat]}};r.getSource("train-base")?r.getSource("train-base").setData(e):r.addSource("train-base",{type:"geojson",data:e}),r.getLayer("train-base")||r.addLayer({id:"train-base",type:"circle",s
12ource:"train-base",paint:{"circle-radius":8,"circle-color":"#000000","circle-opacity":.8}});let t={type:"Feature",geometry:{type:"Point",coordinates:[l.lng,l.lat]},properties:{bearing:l.dir||0}};if(!r.hasImage("train-arrow")){let e=new Image(24,24);e.onload=()=>{r.hasImage("train-arrow")||r.addImage("train-arrow",e)},e.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><polygon points="12,2 22,22 12,17 2,22" fill="#000"/></svg>')}r.getSource("train-arrow")?r.getSource("train-arrow").setData(t):r.addSource("train-arrow",{type:"geojson",data:t}),r.getLayer("train-arrow")||r.addLayer({id:"train-arrow",type:"symbol",source:"train-arrow",layout:{"icon-image":"train-arrow","icon-size":.8,"icon-allow-overlap":!0,"icon-ignore-placement":!0,"icon-rotation-alignment":"map","icon-rotate":["case",["all",["has","bearing"],["==",["typeof",["get","bearing"]],"number"]],["get","bearing"],0]}}),r.getSource("train-pulse")?r.getSource("train-pulse").setData(e):r.addSource("train-pulse",{type:"geojson",data:e}),r.getLayer("train-pulse")||r.addLayer({id:"train-pulse",type:"circle",source:"train-pulse",paint:{"circle-radius":8,"circle-color":"#222222","circle-opacity":.4}}),r.on("click","train-base",e=>{let t=e.features[0].geometry.coordinates.slice();new U.A.Popup({closeButton:!1,closeOnClick:!0,className:"train-popup"}).setLngLat(t).setHTML(` 13 <div class="p-2"> 14 <h3 class="font-bold text-gray-900">Current Train Position</h3> 15 </div> 16 `).addTo(r)}),r.on("mouseenter","train-base",()=>{r.getCanvas().style.cursor="pointer"}),r.on("mouseleave","train-base",()=>{r.getCanvas().style.cursor=""});let s=r.getSource("train-base");s&&s.setData({type:"Feature",geometry:{type:"Point",coordinates:[l.lng,l.lat]}});let a=r.getSource("train-arrow");a&&a.setData({type:"Feature",geometry:{type:"Point",coordinates:[l.lng,l.lat]},properties:{bearing:l.dir||0}}),r.getLayer("train-points")&&r.moveLayer("train-pulse","train-points")}r.getLayer("speed-labels")||r.addLayer({id:"speed-labels",type:"symbol",source:"historical-positions",layout:{"text-field":["get","speed"],"text-size":11,"text-offset":[0,1.2],"text-anchor":"center"},paint:{"text-color":"#000000","text-halo-color":"#ffffff","text-halo-width":1.5}})}catch(e){console.error("Error creating speed line:",e)}};function f(e,t,r){let s=parseInt(e.substring(1,3),16),a=parseInt(e.substring(3,5),16),i=parseInt(e.substring(5,7),16),n=parseInt(t.substring(1,3),16),l=parseInt(t.substring(3,5),16),o=parseInt(t.substring(5,7),16),d=Math.round(s+(n-s)*r),c=Math.round(a+(l-a)*r),p=Math.round(i+(o-i)*r);return`#${(0x1000000+(d<<16)+(c<<8)+p).toString(16).slice(1)}`}return(0,n.useEffect)(()=>{let t;if(!o.current||d.current)return;let s=r||(e?.length>0?[e[0].lng,e[0].lat]:[0,0]);return d.current=new U.A.Map({container:o.current,style:(0,W.pI)(),center:s,zoom:a,antialias:!0}),d.current.on("load",()=>{let e;(0,W.z7)(d.current),x(d.current),(0,O.b)(d.current),c.current=!0;let r=s=>{if(!d.current)return;void 0===e&&(e=s);let a=(s-e)%1500/1500,i=.6*Math.sin(a*Math.PI);d.current.getLayer("train-pulse")&&(d.current.setPaintProperty("train-pulse","circle-radius",27*a),d.current.setPaintProperty("train-pulse","circle-opacity",i)),t=requestAnimationFrame(r)};t=requestAnimationFrame(r)}),()=>{t&&cancelAnimationFrame(t),d.current&&(d.current.remove(),d.current=null,c.current=!1)}},[]),(0,n.useEffect)(()=>{if(!d.current||!c.current)return;d.current.getSource("speed-line")&&x(d.current);let t=d.current.getSource("historical-endpoint");if(t&&e?.length>0){let r=e[0];t.setData({type:"Feature",geometry:{type:"Point",coordinates:[r.lng,r.lat]}})}let r=d.current.getSource("historical-positions");r&&r.setData({type:"FeatureCollection",features:e.slice(0,-1).map(e=>{let t="N/A";return e.normalized?.speed?.has_speed&&(t=g(h(e.normalized.speed.value,e.normalized.speed.unit,m),(0,v.rT)(m))),{type:"Feature",geometry:{type:"Point",coordinates:[e.lng,e.lat]},properties:{updated:e.updated,speed:t}}})})},[e,t,l,m,h,g]),(0,s.jsxs)("div",{style:{position:"relative",width:"100%"},children:[p&&(0,s.jsx)(S,{}),(0,s.jsx)("div",{ref:o,style:{height:`${i}px`,width:"100%"}}),(0,s.jsxs)("div",{style:{position:"absolute",bottom:"1rem",left:"1rem",backgroundColor:"rgba(255, 255, 255, 0.9)",padding:"0.75rem",borderRadius:"0.375rem",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",zIndex:1,maxWidth:"200px",pointerEvents:"none",border:"1px solid rgba(0,0,0,0.1)"},children:[(0,s.jsx)("div",{style:{background:"linear-gradient(to right, #ef4444 0%, #f97316 20%, #eab308 40%, #22c55e 60%, #3b82f6 80%, #6366f1 100%)",height:"0.5rem",borderRadius:"0.25rem",marginBottom:"0.5rem"}}),(0,s.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",fontSize:"0.75rem",color:"#333"},children:[(0,s.jsx)("span",{children:"0 km/h"}),(0,s.jsx)("span",{children:"100+ km/h"})]})]})]})};var V=r(5876),H=r(74880),G=r(91482),Y=r(10714),K=r(21691),Z=r(36122);let J=(0,n.forwardRef)(({train:e,trip:t,initialCenter:r,initialZoom:a=13,height:i=400,network:l,disablePulseAnimation:o=!1},d)=>
16{let[c,p]=(0,n.useState)(!1),[u,m]=(0,n.useState)(()=>Date.now());(0,n.useEffect)(()=>{let e=()=>m(Date.now()),t=setInterval(e,1e3);return document.addEventListener("visibilitychange",e),()=>{clearInterval(t),document.removeEventListener("visibilitychange",e)}},[]);let h=(0,Z.x)(e,u),[,g]=(0,n.useState)(!1),[x,f]=(0,n.useState)(!1),w=(0,n.useRef)(null),j=(0,n.useRef)(null),b=(0,n.useRef)(!1),N=(0,n.useMemo)(()=>H.Y.getAllNetworks(),[]),_=(0,n.useMemo)(()=>{if(!l)return N;let e=(l.slug||"").toLowerCase();return!e||N.some(t=>(t.slug||"").toLowerCase()===e)?N:[...N,l]},[N,l]),k=(0,n.useRef)(null),S=(0,n.useRef)(null),{units:L,convertSpeed:M,formatSpeed:I}=(0,y.t)(),$=(0,n.useRef)(!1),C=(0,n.useRef)(null),A=(0,n.useRef)([]);(0,n.useImperativeHandle)(d,()=>({easeTo:e=>{j.current&&(f(!0),S.current&&S.current.show(),j.current.easeTo(e))}}));let T=e=>{e.getLayer("trip-shape-layer")&&(e.getLayer("trip-stop-labels")?e.moveLayer("trip-shape-layer","trip-stop-labels"):e.getLayer("trip-stops")&&e.moveLayer("trip-shape-layer","trip-stops")),e.getLayer("trip-stops")&&e.moveLayer("trip-stops"),e.getLayer("trip-stop-labels")&&e.moveLayer("trip-stop-labels"),e.getLayer("train-points")&&e.moveLayer("train-points"),e.getLayer("train-pulse")&&e.getLayer("train-points")&&e.moveLayer("train-pulse","train-points")},P=r=>{if(!r.isStyleLoaded())return;let s=r.getStyle();if(!s||!s.layers)return;let a=_.find(t=>(t.slug||"").toLowerCase()===(e.agency||"").toLowerCase()),i=a?.color||"#ff00ff",n=a?.textColor||"#000000",l=t?.shape_points?t.shape_points.map(e=>[parseFloat(e.shape_pt_lon),parseFloat(e.shape_pt_lat)]):null,o=t?.stop_times?t.stop_times.map(e=>({type:"Feature",geometry:{type:"Point",coordinates:[parseFloat(e.stop.stop_lon),parseFloat(e.stop.stop_lat)]},properties:{name:e.stop.stop_name,arrival:e.arrival_time?.split?.(":")?.slice(0,2)?.join(":")||"",departure:e.departure_time?.split?.(":")?.slice(0,2)?.join(":")||"",isTerminal:e.stop_sequence===t.stop_times[0].stop_sequence||e.stop_sequence===t.stop_times[t.stop_times.length-1].stop_sequence}})):[];l&&l.length&&(C.current=l),o&&o.length&&(A.current=o);let d=C.current,c=A.current||[],p=r.getSource("trip-shape");!p&&d&&(r.addSource("trip-shape",{type:"geojson",data:{type:"Feature",geometry:{type:"LineString",coordinates:d}}}),p=r.getSource("trip-shape")),d&&!r.getLayer("trip-shape-layer")&&r.addLayer({id:"trip-shape-layer",type:"line",source:"trip-shape",layout:{"line-join":"round","line-cap":"round"},paint:{"line-color":i,"line-width":3,"line-opacity":.9}}),d&&p&&p.setData({type:"Feature",geometry:{type:"LineString",coordinates:d}});let u=r.getSource("trip-stops");!u&&c.length&&(r.addSource("trip-stops",{type:"geojson",data:{type:"FeatureCollection",features:c}}),u=r.getSource("trip-stops")),c.length&&!r.getLayer("trip-stops")&&r.addLayer({id:"trip-stops",type:"circle",source:"trip-stops",layout:{visibility:"visible"},paint:{"circle-radius":5,"circle-color":i,"circle-stroke-width":2,"circle-stroke-color":n,"circle-opacity":1}}),c.length&&!r.getLayer("trip-stop-labels")&&r.addLayer({id:"trip-stop-labels",type:"symbol",source:"trip-stops",layout:{"text-field":["get","name"],"text-font":["Noto Sans Regular"],"text-variable-anchor":["top","bottom","left","right"],"text-radial-offset":.8,"text-justify":"auto","text-size":["case",["get","isTerminal"],14,12],"text-allow-overlap":!0,"icon-allow-overlap":!0},paint:{"text-color":"#111827","text-halo-color":"#ffffff","text-halo-width":2,"text-halo-blur":.5}}),c.length&&u&&u.setData({type:"FeatureCollection",features:c}),r.getLayer("trip-stop-labels")&&r.moveLayer("trip-stop-labels"),r.getLayer("trip-stops")&&r.moveLayer("trip-stops"),T(r),$.current=!0};return(0,n.useEffect)(()=>{if(!w.current||j.current)return;let t=r||(e?[e.lng,e.lat]:[-98.5795,39.8283]);return j.current=new U.A.Map({container:w.current,style:(0,W.pI)(),center:t,zoom:a,antialias:!0,preserveDrawingBuffer:!1}),j.current.on("load",()=>{b.current=!0,p(!0),(0,W.z7)(j.current);let t=_.find(t=>(t.slug||"").toLowerCase()===(e.agency||"").toLowerCase());(0,G.TL)(j.current,_,Y.A);let r=j.current.getSource("trains");if(r&&e&&(0,Z.x)(e)&&Number.isFinite(e.lat)&&Number.isFinite(e.lng)){let t=[{type:"Feature",geometry:{type:"Point",coordinates:[e.lng,e.lat]},properties:{id:e.id,vid:e.vid,name:e.name,agency:(e.agency||"").toLowerCase(),spd:e.normalized?.speed?.has_speed?`${e.normalized.speed.value}`:"N/A",org:e.org,dst:e.dst,updated_ago:e.updated_ago,gtfs:JSON.stringify(e.gtfs||{}),direction:e.dir}}];r.setData({type:"FeatureCollection",features:t}),(0,K.pt)(t)}P(j.current),j.current.getLayer("trip-stop-labels")&&j.current.moveLayer("trip-stop-labels"),j.current.getLayer("trip-stops")&&j.current.moveLayer("trip-stops"),j.current.getSource("trains")||j.current.addSource("trains",{type:"geojson",data:{type:"FeatureCollection",features:[]}}),j.current.getSource("trains")&&(j.current.getLayer("train-pulse")||j.current.addLayer({id:"train-pulse",type:"circle",s
16ource:"trains",paint:{"circle-radius":10,"circle-color":t?.color||"#000000","circle-opacity":.8}}),j.current.getLayer("train-points")&&j.current.moveLayer("train-pulse","train-points")),T(j.current),S.current=(0,O.E)(j.current,g,{enablePanning:!0,setIsUserPanning:f,train:e,initialMode:"3d",interactiveOnDemand:!0}),(0,K.MB)(j.current)}),()=>{j.current&&(j.current.remove(),j.current=null,b.current=!1)}},[]),(0,n.useEffect)(()=>{if(!j.current||!t)return;let e=()=>{j.current&&b.current&&j.current.isStyleLoaded()&&(P(j.current),T(j.current),j.current.off("styledata",e))};b.current&&j.current.isStyleLoaded()?(P(j.current),T(j.current)):j.current.on("styledata",e)},[t]),(0,n.useEffect)(()=>{let e;if(o||!c||!j.current)return;let t=r=>{if(!j.current)return;void 0===e&&(e=r);let s=(r-e)%1500/1500,a=.6*Math.sin(s*Math.PI);j.current.getLayer("train-pulse")&&(j.current.setPaintProperty("train-pulse","circle-radius",27*s),j.current.setPaintProperty("train-pulse","circle-opacity",a)),k.current=requestAnimationFrame(t)};return k.current=requestAnimationFrame(t),()=>{k.current&&cancelAnimationFrame(k.current)}},[o,c]),(0,n.useEffect)(()=>{if(!j.current||!b.current||!e)return;let t=j.current.getSource("trains");if(!t)return;if(!h){t.setData({type:"FeatureCollection",features:[]}),(0,K.pt)([]);return}let r=Number(e.lat),s=Number(e.lng);if(!Number.isFinite(r)||!Number.isFinite(s))return;let a="N/A";e.normalized?.speed?.has_speed&&(a=I(M(e.normalized.speed.value,e.normalized.speed.unit,L),(0,v.rT)(L)));let i=[{type:"Feature",geometry:{type:"Point",coordinates:[s,r]},properties:{id:e.id,vid:e.vid,name:e.name,agency:(e.agency||"").toLowerCase(),spd:a,org:e.org,dst:e.dst,updated_ago:e.updated_ago,gtfs:JSON.stringify(e.gtfs||{}),direction:e.dir}}];t.setData({type:"FeatureCollection",features:i}),(0,K.pt)(i),P(j.current),T(j.current),x||j.current.easeTo({center:[s,r],duration:1e3})},[e,L,M,I,x,h,c]),(0,s.jsx)("div",{ref:w,style:{height:`${i}px`,width:"100%"},children:!c&&(0,s.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,s.jsx)(V.A,{text:"Loading map..."})})})});J.displayName="TrainMapWithTrip";var X=r(18847),Q=r.n(X),ee=r(48230),et=r.n(ee);r(92);var er=r(78240);let es=Q()(()=>r.e(6698).then(r.bind(r,36698)).then(e=>e.MapContainer),{loadableGenerated:{webpack:()=>[36698]},ssr:!1}),ea=Q()(()=>r.e(6698).then(r.bind(r,36698)).then(e=>e.TileLayer),{loadableGenerated:{webpack:()=>[36698]},ssr:!1}),ei=Q()(()=>r.e(6698).then(r.bind(r,36698)).then(e=>e.Marker),{loadableGenerated:{webpack:()=>[36698]},ssr:!1}),en=Q()(()=>r.e(6698).then(r.bind(r,36698)).then(e=>e.Polyline),{loadableGenerated:{webpack:()=>[36698]},ssr:!1}),el=({train:e})=>{var t;let a,i,l,o,{convertSpeed:d,formatSpeed:c}=(0,y.t)(),p=(0,n.useMemo)(()=>[e.lat,e.lng],[e.lat,e.lng]),{routes:u}=(0,er.L6)(e.agency,e.gtfs?.route_id),m=(0,n.useMemo)(()=>{let e=u?.shapes||[];return(e.length>0&&!Array.isArray(e[0])?[e]:e).map(e=>e.map(e=>[parseFloat(e.lat),parseFloat(e.lon)]).filter(e=>Number.isFinite(e[0])&&Number.isFinite(e[1]))).filter(e=>e.length>=2)},[u]),h=(0,n.useMemo)(()=>{let e=m.flat();if(!e.length)return null;let t=1/0,r=-1/0,s=1/0,a=-1/0;e.forEach(([e,i])=>{e<t&&(t=e),e>r&&(r=e),i<s&&(s=i),i>a&&(a=i)});let i=Math.max(.5*(r-t||.01),.05),n=Math.max(.5*(a-s||.01),.05);return[[t-i,s-n],[r+i,a+n]]},[m]),g=(0,n.useMemo)(()=>{let t=u?.route?.route_color||H.Y.getNetwork(e.agency.toLowerCase())?.color?.replace("#","")||"000000";return`#${t}`},[u,e.agency]),x=(0,n.useMemo)(()=>h?{bounds:h,boundsOptions:{padding:[8,8]}}:{center:p,zoom:13},[h,p]);return(0,s.jsxs)(et(),{href:`/networks/${e.agency}/trains/${e.vid}/`,className:"block group relative rounded-lg overflow-hidden bg-white shadow-md hover:shadow-lg focus-within:ring-2 focus-within:ring-indigo-500 focus-within:ring-offset-2",children:[(0,s.jsx)("div",{className:"h-40 w-full pointer-events-none",children:(0,s.jsxs)(es,{...x,zoomControl:!1,dragging:!1,touchZoom:!1,doubleClickZoom:!1,scrollWheelZoom:!1,attributionControl:!1,boxZoom:!1,keyboard:!1,tap:!1,style:{height:"100%",width:"100%"},children:[(0,s.jsx)(ea,{url:"https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png"}),m.length>0&&(0,s.jsx)(en,{positions:m,pathOptions:{color:g,weight:3,opacity:.85}}),(0,s.jsx)(ei,{position:p,icon:(t=e.agency,a=r(16895),i=H.Y.getNetwork(t?.toLowerCase()),l=i?.color||"#000000",o=i?.darkerColor||"#000000",a.divIcon({className:"custom-icon",html:` 17 <div style="background-color: ${l}; width: 12px; height: 12px; border-radius: 50%; border: 2px solid ${o};"></div> 18 `,iconSize:[16,16],iconAnchor:[8,8]})),interactive:!1})]})}),(0,s.jsxs)("div",{className:"p-4",children:[(0,s.jsx)("h3",{className:"text-xl font-medium text-gray-900",children:e.name||e.
18id}),(0,s.jsx)("p",{className:"mt-1 text-sm text-gray-500",children:e.normalized.speed.has_speed?c(d(e.normalized.speed.value,e.normalized.speed.unit,"kph"),(0,v.rT)("kph")):"No speed data"})]})]})},eo=({currentVehicleId:e,networkSlug:t,routeId:r})=>{let[a,i]=(0,n.useState)(!1),{t:l}=(0,g.B)(),o=(0,er.b1)(t,r).filter(t=>t.vid!==e);if(!o||0===o.length)return(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"text-gray-500 text-center py-8",children:l("otherTrainsNone")}),(0,s.jsx)("div",{className:"flex justify-end mt-4 space-x-4",children:(0,s.jsx)("a",{href:`/networks/${t}/`,className:"inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md shadow-sm text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500",children:l("otherTrainsViewNetwork")})})]});let d=a?o:o.slice(0,8),c=1===o.length?l("otherTrainsCountSingular"):l("otherTrainsCountPlural").replace("{n}",o.length);return(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-gray-600 mb-10",children:c}),(0,s.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-6",children:d.map(e=>(0,s.jsx)(el,{train:e},`${e.vid}-${e.id}`))}),o.length>8&&(0,s.jsx)("div",{className:"text-center mt-6",children:(0,s.jsx)("button",{onClick:()=>i(!a),className:"text-blue-600 hover:text-blue-800 font-medium",children:a?l("otherTrainsShowFewer"):l("otherTrainsViewAll").replace("{n}",o.length)})}),(0,s.jsxs)("div",{className:"flex justify-end mt-4 space-x-4",children:[(0,s.jsx)("a",{href:`/networks/${t}/`,className:"inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md shadow-sm text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500",children:l("otherTrainsViewAllNetwork")}),(0,s.jsx)("a",{href:`/networks/${t}/routes/${r}`,className:"inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md shadow-sm text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500",children:l("otherTrainsViewAllRoute")})]})]})};var ed=r(94292),ec=r(69973);r(50514);var ep=r(73093);let eu=({trip:e,train:t,onStopProgressUpdate:r,highlightColor:a="#3182ce",onStopClick:i,realtimeStopTimes:l})=>{let[o,d]=(0,n.useState)([]),[c,p]=(0,n.useState)(null),{t:u}=(0,g.B)(),m=(0,n.useMemo)(()=>{if(!l)return{};let e={};for(let t of l)e[t.stop_id]=t;return e},[l]);return((0,n.useEffect)(()=>{(async()=>{if(e?.stop_times&&e?.trip_id)try{let s=(await (0,ep.V)(e)).map((t,r)=>{let s=e.stop_times.find(e=>e.stop.stop_id===t.stop_id),a=m[t.stop_id];return{name:t.stop_name,stopId:t.stop_id,arrival:s?.arrival_time||"N/A",departure:s?.departure_time||"N/A",sequence:s?.stop_sequence||r+1,lat:t.stop_lat,lng:t.stop_lon,realtimeArrival:a?.realtime_arrival||null,realtimeDeparture:a?.realtime_departure||null,arrivalDelaySeconds:a?.arrival_delay_seconds??null,departureDelaySeconds:a?.departure_delay_seconds??null,realtimeStatus:a?.status??null}});if(d(s),t?.lat&&t?.lng)try{let s=await (0,ep.K)(e,{position:{lat:t.lat,lon:t.lng}});p(s),r?.(s)}catch(e){console.error("[StopTimeline] Error getting stop progress:",e)}}catch(e){console.error("[StopTimeline] Error processing stops:",e),d([])}})()},[e,t,r,m]),e?.stop_times)?0===o.length?(0,s.jsx)("div",{className:"text-gray-500 text-center py-4",children:u("stopTimelineLoading")}):(0,s.jsx)("div",{children:(0,s.jsx)(ed.A,{items:o,renderItem:e=>{let t=c?.trainIsAtStop?.stop_id===e.stopId,r=c?.previousStops.some(t=>t.stop_id===e.stopId)&&!t,n=c?.nextStops?.[0]?.stop_id===e.stopId;return(0,s.jsx)(ec.A,{stopName:e.name,onClick:()=>i?.(e),highlightColor:a,isPassed:r,isCurrent:t,isNext:n,isFinalStop:e.stopId===o[o.length-1].stopId,arrival:e.arrival,departure:e.departure,realtimeArrival:e.realtimeArrival,realtimeDeparture:e.realtimeDeparture,delaySeconds:e.departureDelaySeconds??e.arrivalDelaySeconds,realtimeStatus:e.realtimeStatus})},connectingLineColor:"bg-gray-200",getLineColor:(e,t)=>{if(!e||!t)return"bg-gray-200";let r=c?.previousStops.some(t=>t.stop_id===e.stopId),s=c?.previousStops.some(e=>e.stop_id===t.stopId),i=c?.nextStops?.[0]?.stop_id===e.stopId,n=c?.nextStops?.[0]?.stop_id===t.stopId,l=c?.trainIsAtStop?.stop_id===e.stopId,o=c?.trainIsAtStop?.stop_id===t.stopId;return r&&s||r&&o||s&&l||r&&n||s&&i?{backgroundColor:a}:"bg-gray-200"}})}):(0,s.jsx)("div",{className:"text-gray-500 text-center py-4",children:u("stopTimelineNoInfo")})};async function em(e,t){try{let r=`${e-3e-4},${t-3e-4},${e+3e-4},${t+3e-4}`,s=` 19 [out:json]; 20 ( 21 way["railway"~"rail|subway|tram"]["maxspeed"](${r}); 22 ); 23 out tags;`,a=`https://overpass-api.de/api/interpreter?data=${encodeURIComponent(s)}`,i=await fetch(a);if(!i.ok)throw Error(`Overpass API error: ${i.statusText}`);let n=await i.json();if(0===n.elements.length)return{error:"NO_RAILWAY_FOUND"};let l=n.elements.map(e=>e.tags?.maxspeed).filter(e=>e);if(l.length>0)return{value:Math.round(Math.max(...l.map(e=>(function(e){if("string"==typeof e){let t=parseFloat(e.replace(/[^\d.]/g,""));return e.includes("mph")?1.60934*t:t}return e})(e))))};return{error:"NO_SPEED_LIMIT"}}catch(e){return console.error("Error fetching train speed limit:",e),{error:"API_ERROR",details:e.message}}}async function eh(e,t){try{let r,s,a,i,n,l,o,d,c,p,u,m=`${e-5e-5},${t-5e-5},${e+5e-5},${t+5e-5}`,h=` 24 [out:json]; 25 ( 26 way["railway"~"rail|subway|tram"](${m}); 27 ); 28 out tags;`,g=`https://overpass-api.de/api/interpreter?data=${encodeURIComponent(h)}`,x=await fetch(g);if(!x.ok)throw Error(`Overpass API error: ${x.statusText}`);let f=await x.json();if(0===f.elements.length)return{error:"NO_RAILWAY_FOUND"};let y={operator:(r=f.elements.map(e=>
28e.tags?.operator).filter(Boolean)).length>0?r[0]:null,owner:(s=f.elements.map(e=>e.tags?.owner).filter(Boolean)).length>0?s[0]:null,electrified:(a=f.elements.map(e=>e.tags?.electrified).filter(Boolean)).includes("yes")||a.includes("contact_line"),gauge:(i=f.elements.map(e=>e.tags?.gauge).filter(Boolean)).length>0?parseInt(i[0]):null,maxSpeed:function(e){let t=e.map(e=>e.tags?.maxspeed).filter(Boolean);if(0===t.length)return null;let r=t[0];return"string"==typeof r&&r.toLowerCase().endsWith("mph")?Math.round(1.60934*parseInt(r)):parseInt(r)}(f.elements),name:(n=f.elements.map(e=>e.tags?.name).filter(Boolean)).length>0?n[0]:null,usage:(l=f.elements.map(e=>e.tags?.usage).filter(Boolean)).length>0?l[0]:null,trafficMode:(o=f.elements.map(e=>e.tags?.["railway:traffic_mode"]).filter(Boolean)).length>0?o[0]:null,division:(d=f.elements.map(e=>e.tags?.["railway:division"]||e.tags?.division).filter(Boolean)).length>0?d[0]:null,subdivision:(c=f.elements.map(e=>e.tags?.["railway:subdivision"]||e.tags?.subdivision).filter(Boolean)).length>0?c[0]:null,railwayRef:(p=f.elements.map(e=>e.tags?.["railway:ref"]).filter(Boolean)).length>0?p[0]:null,railwayLine:(u=f.elements.map(e=>e.tags?.["railway:line"]).filter(Boolean)).length>0?u[0]:null};if(Object.values(y).some(e=>null!==e))return y;return{error:"NO_TRACK_INFO"}}catch(e){return console.error("Error fetching track information:",e),{error:"API_ERROR",details:e.message}}}let eg=({train:e})=>{let[t,r]=(0,n.useState)(null),[a,i]=(0,n.useState)(!0),{units:l,convertSpeed:o}=(0,y.t)(),{t:d}=(0,g.B)();if((0,n.useEffect)(()=>{(async()=>{if(!e?.lat||!e?.lng){i(!1),r(null);return}try{let[t,s]=await Promise.all([em(e.lat,e.lng),eh(e.lat,e.lng)]),a={};t&&!t.error&&"number"==typeof t.value?(a.speedLimit=o(t.value,"kph",l),a.speedUnit=(0,v.rT)(l)):(a.speedLimit=null,a.speedError=t?.error||"UNKNOWN"),s&&!s.error?(a.owner=s.owner||null,a.operator=s.operator||null,a.subdivision=s.subdivision||null,a.division=s.division||null,a.name=s.name||null,a.usage=s.usage||null,a.trafficMode=s.trafficMode||null,a.electrified="boolean"==typeof s.electrified?s.electrified:null,a.gauge=s.gauge||null,a.speedLimit||"number"!=typeof s.maxSpeed||(a.speedLimit=o(s.maxSpeed,"kph",l),a.speedUnit=(0,v.rT)(l),a.speedError=null)):a.trackError=s?.error||"UNKNOWN",r(a)}catch(e){r({error:!0})}finally{i(!1)}})()},[e?.lat,e?.lng,l,o]),a)return(0,s.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-y-2 gap-x-6",children:[(0,s.jsx)("div",{className:"h-6 bg-gray-200 rounded animate-pulse w-1/3"}),(0,s.jsx)("div",{className:"h-6 bg-gray-200 rounded animate-pulse w-1/2"})]});if(!t)return(0,s.jsx)("div",{className:"text-sm text-gray-500",children:d("trackInfoUnavailable")});let c=(0,s.jsx)("span",{className:"text-gray-500",children:d("trackInfoUnknown")}),p="number"==typeof t.speedLimit?(0,s.jsxs)("span",{children:[t.speedLimit," ",(0,s.jsx)("span",{className:"text-gray-500 text-sm",children:t.speedUnit})]}):(0,s.jsx)("span",{className:"text-gray-500",children:d("NO_RAILWAY_FOUND"===t.speedError?"trackInfoNoRailway":"NO_SPEED_LIMIT"===t.speedError?"trackInfoNoSpeedData":"trackInfoSpeedUnavailable")}),u=[{label:d("trackInfoSpeedLimit"),value:p},{label:d("trackInfoOwner"),value:t.owner||c},{label:d("trackInfoOperator"),value:t.operator||c},{label:d("trackInfoSubdivision"),value:t.subdivision||c},{label:d("trackInfoDivision"),value:t.division||c},{label:d("trackInfoLineName"),value:t.name||c},{label:d("trackInfoUsage"),value:t.usage||c},{label:d("trackInfoTrafficMode"),value:t.trafficMode||c},{label:d("trackInfoElectrified"),value:null===t.electrified?c:d(t.electrified?"trackInfoYes":"trackInfoNo")},{label:d("trackInfoGauge"),value:t.gauge?d("trackInfoMm").replace("{value}",t.gauge):c}];return(0,s.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-y-2 gap-x-6",children:u.map(({label:e,value:t})=>(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"text-sm text-gray-500",children:e}),(0,s.jsx)("div",{className:"text-base font-medium text-gray-900",children:t})]},e))})};var ex=r(89214),ef=r(88627),ey=r(49825);let ev=[{question:"What type of train is this?",answer:({train:e})=>{let t=e?.normalized?.vehicle?.type?.name||"Unknown type",r=e?.normalized?.network?.name||"Unknown network";return`This is a ${t} operated by ${r}.`}},{question:"Where is this train going?",answer:({train:e})=>{let t=e?.org||"Unknown",r=e?.dst||"Unknown",s=e?.spd?.value===0;return`This train is traveling from ${t} to ${r}. ${s?"The train is currently stopped at a station or signal.":"It is currently in motion between these locations."}`}},{question:"How fast is it currently moving?",answer:({train:e,settings:t})=>{if(!e?.spd?.value)return"Real-time speed information is not currently available.";if(0===e.spd.value)return"The train is currently stopped.";let{convertSpeed:r,formatSpeed:s}=t,a=r(e.spd.value,e.spd.unit||"km/h",t.units),i=(0,v.rT)(t.units),n=`The train is currently traveling at ${s(a,i)}.`;if(e?.speedLimit&&!e.speedLimit.error){let l=r(e.speedLimit.value,"kph",t.units),o=Math.round(a/l*100);n+=` The track speed limit in this section is ${s(l,i)}, meaning the train is operating at ${o}% of the maximum allowed speed.`}return n}},{question:"When was this information last updated?",answer:({train:e})=>e?.updated_ago?`This information was last updated ${e.updated_ago}.`:"Update time information is not available."},{question:"What is the train's current status?",answer:({train:e})=>e?.spd?.value?0===e.spd.value?"The train is currently stopped, likely at a station or waiting at a signal.":"The train is currently in motion and operating normally.":"Status information is not currently available."}],ew=({train:e})=>{let t=(0,y.t)();return(0,s.jsx)("div",{children:(0,s.jsx)("dl",{className:"space-y-6 divide-y divide-gray-900/10",children:ev.map(r=>(0,s.jsxs)(ex.EN,{as:"div",className:"pt-6",children:[(0,s.jsx)("dt",{children:(0,s.jsxs)(ex._q,{className:"group flex w-full items-start justify-between text-left text-gray-900",children:[(0,s.jsx)("span",{className:"text-base font-semibold leading-7",children:r.question}),(0,s.jsxs)("span",{className:"ml-6 flex h-7 items-center",children:[(0,s.jsx)(ef.A,{"aria-hidden":"true",className:"h-6 w-6 group-data-[open]:hidden"}),(0,s.jsx)(ey.A,{"aria-hidden":"true",className:"h-6 w-6 [.group:not([data-open])_&]:hidden"})]})]})}),(0,s.jsx)(ex.kS,{as:"dd",className:"mt-2 pr-12",children:(0,s.jsx)("p",{className:"text-base leading-7 text-gray-600",children:r.answer({train:e,settings:t})})})]},r.question))})})};var ej=r(7994);function eb(){let{t:e}=(0,g.B)();return(0,s.jsx)(ex.EN,{as:"div",className:"my-10",children:({open:t})=>(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ex.EN.Button,{className:"w-full text-left focus-visible:outline-none",children:(0,s.jsx)("div",{className:"rounded-md bg-blue-50 p-4 transition-colors hover:bg-blue-100",children:(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)("div",{className:"shrink-0",children:(0,s.jsx)(a.A,{"aria-hidden":"true",className:"size-5 text-blue-400"})}),(0,s.jsx)("div",{className:"ml-3 flex-1",children:(0,s.jsx)("p",{className:"text-left text-sm text-blue-700",children:e("tripNotFoundTitle")})}),(0,s.jsx)(ej.A,{className:`ml-3 size-5 text-blue-500 transition-transform ${t?"rotate-180":""}`,"aria-hidden":"true"})]})})}),(0,s.jsx)(ex.EN.Panel,{className:"rounded-b-md bg-blue-50 border-t border-blue-200 px-6 pt-4 pb-6",children:(0,s.jsx)("div",{className:"mt-2 text-sm text-blue-700",children:e("tripNotFoundBody")})})]})})}let eN=e=>(0,s.jsxs)("div",{className:"relative",style:{height:`${e}px`,width:"100%"},children:[(0,s.jsx)("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundImage:"url(/_next/static/media/loading.33269102.png)",backgroundSize:"cover",backgroundPosition:"center",filter:"grayscale(100%) opacity(20%)"}}),(0,s.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,s.jsx)(V.A,{text:"Loading map..."})})]});var e_=r(77604);let ek=(...e)=>fetch(...e).then(e=>e.json());var eS=!0;function eL({network:e}){let{networkSlug:t,vehicleId:r}=(0,i.useRouter)().query,{t:h}=(0,g.B)(),{positions:f,isLoading:y,isError:v}=(0,er.jC)(t,r),{trains:w}=(0,er.s1)(),{trains:N}=(0,er._I)(t),{trains:_,isLoading:k}
28=(0,er.Vb)(t),S=(0,n.useRef)(null),[M,I]=(0,n.useState)(null),[$,C]=(0,n.useState)(null),[A,T]=(0,n.useState)(!1),P=(0,u.A)({networkName:e?.name,networkSlug:t,network:e}),D=e=>{S.current&&S.current.easeTo({center:[e.lng,e.lat],duration:1e3})},F=(0,n.useMemo)(()=>"string"==typeof r&&r.startsWith("ghost_"),[r]),E=(0,n.useMemo)(()=>"string"==typeof r&&r.startsWith("synth_"),[r]),R=(0,n.useMemo)(()=>f?.positions?.length?f.positions[f.positions.length-1]:null,[f]),B=(0,n.useMemo)(()=>F&&w?.trains&&w.trains.find(e=>e.vid===r&&e.agency&&String(e.agency).toLowerCase()===String(t).toLowerCase())||null,[F,w,r,t]),U=(0,n.useMemo)(()=>_?.length&&_.find(e=>e.vid===r)||null,[_,r]),O=(0,n.useMemo)(()=>N?.length&&N.find(e=>e.vid===r)||null,[N,r]),W=E||U?.position_source==="trip_update_synth",V=(0,n.useMemo)(()=>B||(O&&U?{...O,gtfs:U.gtfs}:O||R),[B,U,O,R]),H=(0,n.useMemo)(()=>!!V?.isGhost||!!W||f?.vehicle?.active!==!1,[f,V,W]),G=(0,n.useMemo)(()=>{if(!V)return null;let e=new Date(V.updated);return Math.floor((new Date-e)/864e5)>7?e.toLocaleDateString():(0,e_.ak)(V.updated)},[V]),{data:Y}=(0,l.Ay)(V?.gtfs?.trip_id?`${er.QU}/api/v3/${t}/trips/${V.gtfs.trip_id}/`:null,ek),{stopTimes:K,tripDelay:Z,tripStatus:X}=(0,er._i)(t,V?.gtfs?.trip_id),Q=[{name:h("networks"),href:"/networks",current:!1},{name:e?.name||"Network",href:`/networks/${t}/`,current:!1},{name:h("trainBreadcrumbTrains"),href:`/networks/${t}/`,current:!1},{name:V?.name||r,href:`/networks/${t}/trains/${r}/`,current:!0}];if((0,n.useEffect)(()=>{(async()=>{V?.lat&&V?.lng&&I(await em(V.lat,V.lng))})()},[V?.lat,V?.lng]),(0,n.useEffect)(()=>{window.gtag&&e&&V&&window.gtag("event","page_view",{page_title:`${e.name} Train ${V.name} | trains.fyi`,page_location:window.location.href,page_path:`/networks/${t}/trains/${r}/`})},[e,V,t,r]),v&&!F&&!W&&!k)return(0,s.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,s.jsx)(p.A,{title:"Error Loading Train Data",description:"There was an error loading the train data. Please try again later.",canonical:`/networks/${t}/trains/${r}/`,image:"/social.png",type:"website"}),(0,s.jsx)(c.A,{networkNav:P}),(0,s.jsx)("main",{className:"flex-grow",children:(0,s.jsx)("div",{className:"mx-auto max-w-7xl px-4 sm:px-6 lg:px-8 py-8",children:(0,s.jsxs)("div",{className:"rounded-md bg-red-50 p-4",children:[(0,s.jsx)("h3",{className:"text-sm font-medium text-red-800",children:h("trainErrorTitle")}),(0,s.jsx)("p",{className:"mt-2 text-sm text-red-700",children:h("trainErrorDesc")})]})})}),(0,s.jsx)(d.A,{})]});if(!e)return(0,s.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,s.jsx)(p.A,{title:"Network Not Found",description:"The requested transit network could not be found.",canonical:`/networks/${t}/trains/${r}/`,image:"/social.png",type:"website"}),(0,s.jsx)(c.A,{}),(0,s.jsx)("main",{className:"flex-grow",children:(0,s.jsx)("div",{className:"mx-auto max-w-7xl px-4 sm:px-6 lg:px-8 py-8",children:(0,s.jsxs)("div",{className:"rounded-md bg-yellow-50 p-4",children:[(0,s.jsx)("h3",{className:"text-sm font-medium text-yellow-800",children:h("trainNetworkNotFound")}),(0,s.jsx)("p",{className:"mt-2 text-sm text-yellow-700",children:h("trainNetworkNotFoundDesc")})]})})}),(0,s.jsx)(d.A,{})]});let ee=!!V?.isGhost,et=V?`${e.name} Train ${V.name}`:`${e.name} Train ${r}`,es=V?ee?`View the scheduled position and route for ${e.name} ${V.normalized.vehicle.type.name||"train"} ${V.name} from ${V.org||"origin"} to ${V.dst||"destination"}.`:`Track ${e.name} ${V.normalized.vehicle.type.name||"train"} ${V.name} in real-time from ${V.org||"origin"} to ${V.dst||"destination"}.`:`Track ${e.name} train ${r} in real-time.`,ea=V?`${e.name}, train ${V.name}, ${V.normalized.vehicle.type.name||"train"} tracker, ${V.org||""}, ${V.dst||""}${ee?", scheduled position":", real-time train tracking"}`:`${e.name}, train ${r}, train tracker, real-time train tracking`,ei=V?.name||r,en=`/api/og?mode=train&network=${encodeURIComponent(e.name)}&train=${encodeURIComponent(ei)}${V?.org?`&origin=${encodeURIComponent(V.org)}`:""}${V?.dst?`&destination=${encodeURIComponent(V.dst)}`:""}&bg=${encodeURIComponent(e.color||"1e3a8a")}&tc=${encodeURIComponent(e.textColor||"ffffff")}`;return(0,s.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,s.jsx)(p.A,{title:et,description:es,canonical:`/networks/${t}/trains/${r}/`,image:en,type:"website",keywords:ea}),(0,s.jsx)(c.A,{networkNav:P}),(0,s.jsx)("main",{className:"flex-grow",children:(0,s.jsxs)("div",{className:"mx-auto max-w-7xl px-4 sm:px-6 lg:px-8",children:[(0,s.jsx)("div",{className:"py-4",children:(0,s.jsx)(o.A,{pages:Q})}),(0,s.jsxs)("div",{className:"my-8",children:[(0,s.jsx)("h1",{className:"text-3xl font-bold mb-0 text-gray-900",children:h("trainPageTitle").replace("{network}",e?.name||"Network")}),(0,s.jsx)("div",{className:"text-xl text-gray-500 flex items-center",children:y?(0,s.jsx)("div",{className:"animate-pulse bg-gray-200 h-8 w-2/3 rounded"}):(0,s.jsxs)("span",{children:[h(ee?"trainShowingScheduled":"trainTracking")," ",e?.name||""," ",V?.normalized.vehicle.type.name||"train"," ",V?.n
28ame," from ",V?.org||"Unknown"," to"," ",V?.dst||"Unknown"]})})]}),ee&&(0,s.jsx)("div",{className:"my-4",children:(0,s.jsx)("div",{className:"rounded-md bg-amber-50 border border-amber-100 p-4 mb-8",children:(0,s.jsxs)("div",{className:"flex",children:[(0,s.jsx)("div",{className:"flex-shrink-0",children:(0,s.jsx)(a.A,{className:"h-5 w-5 text-amber-400","aria-hidden":"true"})}),(0,s.jsxs)("div",{className:"ml-3",children:[(0,s.jsx)("h3",{className:"text-sm font-medium text-amber-800",children:h("trainScheduledPosition")}),(0,s.jsx)("div",{className:"mt-2 text-sm text-amber-700",children:(0,s.jsx)("p",{children:h("trainNoGps")})})]})]})})}),!H&&V&&(0,s.jsx)("div",{className:"my-4",children:(0,s.jsx)("div",{className:"rounded-md bg-amber-50 p-4 mb-8",children:(0,s.jsxs)("div",{className:"flex",children:[(0,s.jsx)("div",{className:"flex-shrink-0",children:(0,s.jsx)("svg",{className:"h-5 w-5 text-amber-400",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,s.jsx)("path",{fillRule:"evenodd",d:"M8.485 2.495c.673-1.167 2.357-1.167 3.03 0l6.28 10.875c.673 1.167-.17 2.625-1.516 2.625H3.72c-1.347 0-2.189-1.458-1.515-2.625L8.485 2.495zM10 5a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 0110 5zm0 9a1 1 0 100-2 1 1 0 000 2z",clipRule:"evenodd"})})}),(0,s.jsxs)("div",{className:"ml-3",children:[(0,s.jsx)("h3",{className:"text-sm font-medium text-amber-800",children:h("trainNotActive")}),(0,s.jsx)("div",{className:"mt-2 text-sm text-amber-700",children:(0,s.jsx)("p",{children:h("trainLastActive").replace("{time}",G)})})]})]})})}),!V?.gtfs?.trip_id&&!y&&(0,s.jsx)("div",{className:"mb-4",children:(0,s.jsx)(eb,{})}),V?.gtfs?.trip_id&&!Y&&(0,s.jsx)("div",{className:"mb-4",children:(0,s.jsx)("div",{className:"rounded-md bg-blue-50 p-4",children:(0,s.jsxs)("div",{className:"flex",children:[(0,s.jsx)("div",{className:"flex-shrink-0",children:(0,s.jsxs)("svg",{className:"animate-spin h-5 w-5 text-blue-400",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[(0,s.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,s.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})}),(0,s.jsxs)("div",{className:"ml-3",children:[(0,s.jsx)("h3",{className:"text-sm font-medium text-blue-800",children:h("trainLoadingSchedule")}),(0,s.jsx)("div",{className:"mt-2 text-sm text-blue-700",children:(0,s.jsx)("p",{children:h("trainLoadingScheduleDesc")})})]})]})})}),(0,s.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-7 gap-4",children:[(0,s.jsxs)("div",{className:"lg:col-span-2 space-y-4",children:[(0,s.jsx)(b,{train:V,stopProgress:$}),!ee&&(0,s.jsx)(j,{train:V,speedLimit:M}),!ee&&(0,s.jsx)(x,{tripDelay:Z,tripStatus:X})]}),(0,s.jsx)("div",{className:"lg:col-span-5",children:(0,s.jsxs)("div",{className:"relative h-[600px]",children:[V?(0,s.jsx)(J,{ref:S,train:V,trip:Y,height:600,historicalPositions:f?.positions||[],network:e}):eN(600),y&&V&&(0,s.jsx)("div",{className:"absolute inset-0 pointer-events-none",children:eN(600)})]})})]}),(0,s.jsx)(m.I,{networkSlug:t,routeIds:V?.gtfs?.route_id?[V.gtfs.route_id]:[],tripIds:V?.gtfs?.trip_id?[V.gtfs.trip_id]:[],stopIds:Y?.stop_times?.map(e=>e.stop_id)||[],className:"mt-4"}),V?.gtfs?.route_id&&(0,s.jsxs)("div",{className:"flex justify-end mt-4 space-x-4",children:[(0,s.jsx)("a",{href:`/networks/${t}/`,className:"inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md shadow-sm text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500",children:h("trainViewAllTrains").replace("{name}",e?.name)}),(0,s.jsx)("a",{href:`/networks/${t}/routes/${V.gtfs.route_id}`,className:"inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md shadow-sm text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500",children:h("trainViewRoute")})]}),Y&&(0,s.jsxs)("div",{className:"mt-10",children:[(0,s.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,s.jsxs)("div",{children:[(0,s.jsx)("h5",{className:"text-xl font-bold text-gray-800",children:h("trainStopTimeline")}),(0,s.jsx)("p",{className:"text-base text-gray-600",children:h(K?"trainStopTimelineRealtime":"trainStopTimelineScheduled")})]})}),Y.stop_times&&Y.stop_times.length>50&&!A?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex items-center justify-between p-4 bg-white border rounded-lg shadow-sm",children:[(0,s.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,s.jsx)(a.A,{className:"h-5 w-5 text-gray-400","aria-hidden":"true"}),(0,s.jsx)("span",{className:"text-sm text-gray-600",children:h("trainManyStops")})]}),(0,s.jsxs)("button",{onClick:()=>T(!0),className:"inline-flex items-center text-sm font-medium text-blue-600 hover:text-blue-500",children:[h("trainShowAllStops").replace("{count}",Y.stop_times.length),(0,s.jsx)("svg",{className:"ml-1.5 h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]})]}),(0,s.jsx)("div",{className:"hidden",children:(0,s.jsx)(eu,{trip:Y,networkSlug:t,train:V,onStopProgressUpdate:C,highlightColor:e?.color,onStopClick:D,realtimeStopTimes:K})})]}):(0,s.jsx)(eu,{trip:Y,networkSlug:t,train:V,onStopProgressUpdate:C,highlightColor:e?.color,onStopClick:D,realtimeStopTimes:K})]}),(0,s.jsx)("h2",{className:"text-2xl font-bold text-gray-900 mb-4 mt-24",children:h("trainVehicleDetails")}),y&&!ee?(0,s.jsx)("div",{className:"animate-pulse space-y-4",children:(0,s.jsx)("div",{className:"bg-gray-200 h-40 rounded"})}):(0,s.jsx)(z,{train:V,speedLimit:M,stopProgress:$}),!ee&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("h2",{className:"text-2xl font-bold mt-24 mb-10 text-gray-900",children:h("trainHistoricalInfo")}),(0,s.jsx)("div",{className:"h-[400px]",children:f?.positions?(0,s.jsx)(L,{trainPositions:f.positions}):(0,s.jsx)("div",{className:"animate-pulse space-y-4",children:(0,s.jsx)("div",{className:"bg-gray-200 h-64 roun
28ded"})})})]}),Y&&!ee&&(0,s.jsxs)("div",{className:"mt-10",children:[(0,s.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,s.jsxs)("div",{children:[(0,s.jsx)("h5",{className:"text-xl font-bold text-gray-800",children:h("trainSpeedHistory")}),(0,s.jsx)("p",{className:"text-base text-gray-600",children:h("trainSpeedHistoryDesc")})]})}),(0,s.jsx)("div",{className:"h-[400px]",children:(0,s.jsx)(q,{historicalPositions:f?.positions||[],trip:Y,initialCenter:[V?.lng,V?.lat],height:300,train:V})})]}),(0,s.jsx)("hr",{className:"my-10"}),(0,s.jsxs)("div",{className:"mt-10",children:[(0,s.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-2xl font-bold text-gray-900 mb-0",children:h("trainTrackInfra")}),(0,s.jsx)("p",{className:"text-base text-gray-600",children:h("trainTrackInfraDesc")})]})}),(0,s.jsx)(eg,{train:V})]}),(0,s.jsx)("hr",{className:"my-10"}),(0,s.jsxs)("div",{className:"mb-10",children:[(0,s.jsx)("h2",{className:"text-2xl font-bold text-gray-900 mb-0",children:h("trainOtherTrains")}),(0,s.jsx)(eo,{currentVehicleId:V?.vid,networkSlug:t,routeId:V?.gtfs?.route_id})]}),(0,s.jsx)("hr",{className:"my-10 mt-20"}),(0,s.jsx)("h2",{className:"text-2xl font-bold tracking-tight text-gray-900 mt-24 mb-4 max-w-4xl mx-auto",children:h("trainDetailsFaq")}),(0,s.jsx)("div",{className:"h-auto mb-8 max-w-4xl mx-auto",children:y?(0,s.jsx)("div",{className:"animate-pulse space-y-4",children:(0,s.jsx)("div",{className:"bg-gray-200 h-32 rounded"})}):(0,s.jsx)(ew,{train:{...V,speedLimit:M}})})]})}),(0,s.jsx)(d.A,{})]})}},49798:(e,t,r)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/networks/[networkSlug]/trains/[vehicleId]",function(){return r(38534)}])},50514:()=>{},73093:(e,t,r)=>{"use strict";r.d(t,{K:()=>o,V:()=>d});let s=e=>e*Math.PI/180,a=e=>180*e/Math.PI,i=(e,t,r,a)=>{let i=s(e),n=s(r),l=s(r-e),o=s(a-t),d=Math.sin(l/2)*Math.sin(l/2)+Math.cos(i)*Math.cos(n)*Math.sin(o/2)*Math.sin(o/2);return 2*Math.atan2(Math.sqrt(d),Math.sqrt(1-d))*6371e3},n=(e,t,r,i)=>{let n=s(e),l=s(t),o=s(r),d=s(i);return(a(Math.atan2(Math.sin(d-l)*Math.cos(o),Math.cos(n)*Math.sin(o)-Math.sin(n)*Math.cos(o)*Math.cos(d-l)))+360)%360},l=(e,t,r,l,o,d)=>{let c=i(r,l,e,t),p=i(o,d,e,t),u=s(n(r,l,o,d)),m=s(n(r,l,e,t));if(0>Math.cos(m-u))return{lat:r,lon:l,distance:c};let h=s(n(o,d,r,l));if(0>Math.cos(s(n(o,d,e,t))-h))return{lat:o,lon:d,distance:p};let g=c/6371e3,x=Math.asin(Math.sin(g)*Math.sin(m-u)),f=Math.acos(Math.cos(g)/Math.cos(x)),y=s(r),v=s(l),w=Math.asin(Math.sin(y)*Math.cos(f)+Math.cos(y)*Math.sin(f)*Math.cos(u)),j=Math.atan2(Math.sin(u)*Math.sin(f)*Math.cos(y),Math.cos(f)-Math.sin(y)*Math.sin(w));return{lat:a(w),lon:a(v+j),distance:Math.abs(6371e3*x)}},o=async(e,t)=>{if(!e.shape_points||0===e.shape_points.length)throw Error("No shape data available for this trip");let r=e.shape_points.sort((e,t)=>e.shape_pt_sequence-t.shape_pt_sequence),s=1/0,a=null,n=-1;for(let e=0;e<r.length-1;e++){let i=l(t.position.lat,t.position.lon,r[e].shape_pt_lat,r[e].shape_pt_lon,r[e+1].shape_pt_lat,r[e+1].shape_pt_lon);i.distance<s&&(s=i.distance,a=i,n=e)}if(s>500)throw Error(`Train is significantly off the expected route (${s.toFixed(0)}m)`);let o=Array(r.length);o[0]=0;for(let e=1;e<r.length;e++)o[e]=o[e-1]+i(r[e-1].shape_pt_lat,r[e-1].shape_pt_lon,r[e].shape_pt_lat,r[e].shape_pt_lon);let d=o[r.length-1],c=o[n]+i(r[n].shape_pt_lat,r[n].shape_pt_lon,a.lat,a.lon),p=c/d,u=e.stop_times.map(e=>{let t=e.stop,s=1/0,a=0;for(let e=0;e<r.length-1;e++){let n=l(t.stop_lat,t.stop_lon,r[e].shape_pt_lat,r[e].shape_pt_lon,r[e+1].shape_pt_lat,r[e+1].shape_pt_lon);n.distance<s&&(s=n.distance,a=(o[e]+i(r[e].shape_pt_lat,r[e].shape_pt_lon,n.lat,n.lon))/d)}return{stop:t,progress:a,distanceToRoute:s}}).sort((e,t)=>e.progress-t.progress),m=u.find(({stop:e})=>100>=i(t.position.lat,t.position.lon,e.stop_lat,e.stop_lon)),h=-1;m?h=u.findIndex(e=>e.stop.stop_id===m.stop.stop_id):-1!==(h=u.slice().reverse().findIndex(e=>e.progress<p))&&(h=u.length-1-h);let g=u.slice(0,h+1).map(e=>e.stop),x=u.slice(h+1).map(e=>e.stop),f=null,y=h>-1?u[h]:null,v=h+1<u.length?u[h+1]:null;if(y&&v&&v.progress>y.progress){let e=p-y.progress,t=v.progress-y.progress;f={percent:t>0?e/t:0,distance:e*d/1e3,totalDistance:t*d/1e3}}return{previousStops:g,nextStops:x,trainIsAtStop:m?.stop||null,progressAlongTotalRoute:{percent:p,distance:c/1e3,totalDistance:d/1e3},progressBetweenStops:f}},d=async e=>{try{return e.stop_times.sort((e,t)=>
28e.stop_sequence-t.stop_sequence).map(e=>e.stop)}catch(e){throw console.error("Error fetching stops in order:",e),e}}}},e=>{e.O(0,[6701,3368,1805,2697,3927,2325,1808,8638,1397,3990,8447,5392,7707,4503,9074,636,6593,8792],()=>e(e.s=49798)),_N_E=e.O()}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.