1import{j as a,c as $,r as h}from"./chunk-LFPYN7LY-BYCOceFh.js";import{p as I,d as P,s as W,a as H}from"./MapControlContext-CaZ7lMlQ.js";import{u as U,r as q,a as M,b as R}from"./GeolocationPermissionContext-BNsxlLYQ.js";import{u as E,B as j,T as y}from"./index-B19M7xEA.js";import{s as B,V as D}from"./time-DAo_j7jH.js";import{T as V}from"./Tag-DsMa3Eur.js";import{V as C}from"./v-stack-C2JudPXh.js";import{H as F}from"./alerts-mA4EJBuF.js";import{D as k,f as K}from"./nearbyStopsService-D1T8Cnfb.js";import{c as Y}from"./create-icon-CgxNfmBl.js";import{c as _,f as G}from"./use-style-config-ZxeY2J_M.js";import{B as X}from"./button-LMyeCesN.js";import{I as J}from"./icon-BoqpEvxL.js";const L=_("div",{baseStyle:{display:"flex",alignItems:"center",justifyContent:"center"}});L.displayName="Center";const Q={horizontal:{insetStart:"50%",transform:"translateX(-50%)"},vertical:{top:"50%",transform:"translateY(-50%)"},both:{insetStart:"50%",top:"50%",transform:"translate(-50%, -50%)"}};G(function(t,i){const{axis:l="both",...r}=t;return a.jsx(_.div,{ref:i,__css:Q[l],...r,position:"absolute"})});const Z=3e4,ee="0 4px 7px rgba(0, 0, 0, 0.3)";function te(e){const t=B(e);return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit"}):null}function ne(e){return e?"scheduled at":"arriving at"}function se(e,t){var u,n,s;const i=String(t),l=(u=e.route)==null?void 0:u.id;if(l!=null&&l!==""&&String(l)===i)return!0;const r=(s=(n=e.pattern)==null?void 0:n.route)==null?void 0:s.id;return r!=null&&r!==""&&String(r)===i}function ae({subtitleStyle:e,bodyFontFamily:t,arrivalClock:i,schedulePrediction:l,route:r,direction:u}){const n={fontSize:e==null?void 0:e.fontSize,fontWeight:e==null?void 0:e.fontWeight,color:e==null?void 0:e.color,fontFamily:(e==null?void 0:e.fontFamily)||t},s=r?a.jsx(V,{backgroundColor:r.color??void 0,color:r.textColor??void 0,minW:0,flexShrink:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",children:r.shortName}):null,d=u?a.jsx(y,{...n,flex:1,minW:0,noOfLines:1,overflow:"hidden",textAlign:"left",title:u,style:{textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u}):null,c=!!(r||u);return a.jsxs(F,{spacing:2,align:"center",w:"100%",minW:0,children:[i?a.jsxs(y,{...n,flexShrink:0,whiteSpace:"nowrap",children:[ne(l)," ",i.toLowerCase()]}):null,i&&c?a.jsxs(F,{spacing:2,align:"center",flex:1,minW:0,children:[a.jsx(y,{...n,flexShrink:0,children:"|"}),s,d]}):null,!i&&c?a.jsxs(F,{spacing:2,align:"center",flex:1,minW:0,children:[d,s]}):null]})}function O({stop:e,route:t,direction:i,secondsToArrival:l,schedulePrediction:r,onClick:u}){var o,p,m,x;const{theme:n}=E(),s=n.components.nearbyStopRow,d=n.typography.fontFamily.body,c=typeof l=="number"?te(l):null,f=[`View arrivals for ${e.name}.`,c?r?`Scheduled arrival at ${c}.`:`Arriving at ${c}.`:null,i?`${i}.`:null,t!=null&&t.shortName?`Route ${t.shortName}.`:null].filter(Boolean).join(" ");return a.jsx(j,{as:"li",listStyleType:"none",m:0,children:a.jsx(j,{as:"button",type:"button",role:"link",bg:s==null?void 0:s.backgroundColor,borderRadius:s==null?void 0:s.borderRadius,boxShadow:s==null?void 0:s.shadow,cursor:"pointer",px:4,py:0,w:"100%",textAlign:"left",transition:"all 0.2s ease",onClick:()=>u(e),_hover:{boxShadow:ee,opacity:.9,"--row-title-underline-opacity":"1"},"aria-label":f,children:a.jsxs(C,{spacing:0,align:"stretch",w:"100%",py:2,children:[a.jsx(y,{fontSize:(o=s==null?void 0:s.title)==null?void 0:o.fontSize,fontWeight:(p=s==null?void 0:s.title)==null?void 0:p.fontWeight,color:(m=s==null?void 0:s.title)==null?void 0:m.color,fontFamily:((x=s==null?void 0:s.title)==null?void 0:x.fontFamily)||d,display:"block",maxW:"100%",w:"fit-content",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",sx:{position:"relative","&::after":{content:'""',position:"absolute",left:0,right:0,bottom:"1px",height:"2px",backgroundColor:"currentColor",pointerEvents:"none",opacity:"var(--row-title-underline-opacity, 0)",transition:"opacity 0.2s ease"}},children:e.name}),a.jsx(ae,{subtitleStyle:s==null?void 0:s.subtitle,bodyFontFamily:d,arrivalClock:c,schedulePrediction:r,route:t??null,direction:i??null})]})})})}function re({stop:e,routeId:t,onClick:i}){var c;const l=$(),[r,u]=h.useState([]);h.useEffect(()=>{let f=!1,o=0,p=null;async function m(x){const N=++o;try{let b=(await P(e.id)).filter(g=>typeof g.secondsToArrival=="number");t&&(b=b.filter(g=>se(g,t)));const S=b.sort((g,A)=>(g.secondsToArrival??Number.POSITIVE_INFINITY)-(A.secondsToArrival??Number.POSITIVE_INFINITY));if(f||N!==o)return;u(S)}catch(v){if(console.error("[NearbyStopRow] Failed to load arrivals:",{stopId:e.id,error:v}),f||N!==o)return;x&&u([])}}return m(!0),p=setInterval(()=>void m(!1),Z),()=>{f=!0,p!=null&&clearInterval(p)}},[e.id,t]);const n=r[0],s=(n==null?void 0:n.route)??((c=n==null?void 0:n.pattern)==null?void 0:c.route),d=f=>{var o;if(i){i(f);return}t&&l(W(t,f.id,(n==null?void 0:n.pattern)??null),{state:{stopName:f.name,stopCode:f.
1stopCode,directionName:I(n==null?void 0:n.pattern)||((o=n==null?void 0:n.pattern)==null?void 0:o.name)||void 0,stopLat:f.lat,stopLon:f.lon,fromNearbyStops:!0}})};return a.jsx(O,{stop:e,route:s,direction:I(n==null?void 0:n.pattern)||void 0,secondsToArrival:typeof(n==null?void 0:n.secondsToArrival)=="number"?n.secondsToArrival:void 0,schedulePrediction:n==null?void 0:n.schedulePrediction,onClick:d})}const oe=Y({displayName:"LocationIcon",viewBox:"0 0 17 17",path:a.jsx("g",{stroke:"none",fill:"none",transform:"translate(0, 1)",fillRule:"evenodd",children:a.jsx("polygon",{fill:"currentColor",transform:"translate(9.1924, 6.7782) scale(-1, 1) rotate(-45) translate(-9.1924, -6.7782)",points:"9.19238816 0.278174593 13.6923882 13.2781746 9.19941941 10.5223152 4.69238816 13.2781746"})})});function w(e){const t=e.components.groupingCaption;return{fontSize:t==null?void 0:t.fontSize,fontWeight:t==null?void 0:t.fontWeight,color:t==null?void 0:t.color,fontFamily:t==null?void 0:t.fontFamily,sx:{WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale"}}}function ie({listingCount:e,listingKind:t,showInlineLoader:i=!1}){const{theme:l}=E(),r=t==="arrival"?e===0?". No nearby stops with arrival times.":e===1?". There is 1 arrival listing.":`. There are ${e} arrival listings.`:e===1?". There is 1 stop nearby.":`. There are ${e} stops nearby.`;return a.jsxs(F,{align:"center",spacing:3,mb:3,children:[a.jsxs(y,{...w(l),children:["Nearby Stops",a.jsx(D,{children:r})]}),i?a.jsx(k,{size:"small",accessibilityText:"Refreshing nearby stops..."}):null]})}function Le({children:e}){const t=U(),{theme:i}=E();return t==="pending"?a.jsxs(j,{mb:6,children:[a.jsx(y,{as:"h2",...w(i),mb:3,children:"Nearby Stops"}),a.jsx(L,{children:a.jsx(k,{size:"medium",accessibilityText:"Checking location permission..."})})]}):t==="granted"?a.jsx(a.Fragment,{children:e}):t==="denied"||t==="unsupported"?null:a.jsxs(j,{mb:6,children:[a.jsx(y,{as:"h2",...w(i),mb:3,children:"Nearby Stops"}),a.jsx(L,{children:a.jsxs(X,{backgroundColor:"#6E7581",color:"white",paddingLeft:"16px",paddingRight:"24px",marginTop:"1.5rem",_hover:{bg:"#2C3242",opacity:1},_active:{bg:"#2C3242",opacity:.8},"aria-label":"Show nearby arrivals","aria-description":"Asks browser for location permission",onClick:()=>q(),children:[a.jsx(J,{as:oe,color:"white",marginRight:"16px"}),"Show nearby arrivals"]})})]})}function Te({arrivalRows:e,stops:t=[],navigateRouteId:i,isLoading:l=!1,hasCompletedInitialLoad:r=!1,onStopClick:u}){const n=$(),s=e!==void 0,d=s?e.length:t.length,c=l&&!r,f=l&&r;return a.jsxs(j,{mb:6,children:[a.jsx(ie,{listingCount:d,listingKind:s?"arrival":"stop",showInlineLoader:f}),c&&a.jsx(L,{children:a.jsx(k,{accessibilityText:"Loading nearby stops...",size:"medium"})}),s&&e.length===0&&r&&!c&&a.jsx(L,{children:a.jsx(y,{textAlign:"center",maxW:"md",px:4,color:"gray.600",fontSize:"md",role:"status",paddingTop:"1.5rem",children:"No nearby stops with arrival times."})}),s&&e.length>0&&!c&&a.jsx(C,{as:"ul",role:"list",spacing:3,align:"stretch",m:0,p:0,children:e.map((o,p)=>a.jsx(O,{stop:o.stop,route:o.route,direction:I(o.pattern)||void 0,secondsToArrival:o.secondsToArrival,schedulePrediction:o.schedulePrediction,onClick:m=>{if(u){u(m);return}n(W(o.route.id,o.stop.id,o.pattern),{state:{stopName:o.stop.name,stopCode:o.stop.stopCode,directionName:I(o.pattern)||o.pattern.name||void 0,stopLat:o.stop.lat,stopLon:o.stop.lon,fromNearbyStops:!0}})}},`${o.stop.id}-${o.pattern.id}-${p}`))}),!s&&t.length>0&&!c&&a.jsx(C,{as:"ul",role:"list",spacing:3,align:"stretch",m:0,p:0,children:t.map((o,p)=>a.jsx(re,{stop:o,routeId:i,onClick:u},`${o.id}-${o.name}-${p}`))})]})}function le(e,t){if(!e||!t)return console.error("[geoUtils] Invalid coordinates provided to calculateDistance:",{coord1:e,coord2:t}),NaN;if(typeof e.lat!="number"||typeof e.lon!="number"||typeof t.lat!="number"||typeof t.lon!="number")return console.error("[geoUtils] Coordinate values must be numbers:",{coord1:e,coord2:t}),NaN;if(!isFinite(e.lat)||!isFinite(e.lon)||!isFinite(t.lat)||!isFinite(t.lon))return console.error("[geoUtils] Coordinate values must be finite numbers:",{coord1:e,co
1ord2:t}),NaN;if(e.lat<-90||e.lat>90||t.lat<-90||t.lat>90)return console.error("[geoUtils] Latitude must be between -90 and 90:",{coord1:e,coord2:t}),NaN;if(e.lon<-180||e.lon>180||t.lon<-180||t.lon>180)return console.error("[geoUtils] Longitude must be between -180 and 180:",{coord1:e,coord2:t}),NaN;const i=3959,l=T(e.lat),r=T(t.lat),u=T(t.lat-e.lat),n=T(t.lon-e.lon),s=Math.sin(u/2)*Math.sin(u/2)+Math.cos(l)*Math.cos(r)*Math.sin(n/2)*Math.sin(n/2),d=2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s)),c=i*d;return!isFinite(c)||c<0?(console.error("[geoUtils] Calculated distance is invalid:",c,{coord1:e,coord2:t}),NaN):c}function T(e){return e*(Math.PI/180)}function ce(e,t,i=3){const l=t.map(r=>({...r,distance:le(e,r)}));return l.sort((r,u)=>r.distance-u.distance),l.slice(0,i)}const ue=3e4;function z(e){return e!=null&&Number.isFinite(e.lat)&&Number.isFinite(e.lng)}function Fe(e=5){const t=M(),i=R(),[l,r]=h.useState([]),[u,n]=h.useState(!1),[s,d]=h.useState(!1),c=h.useRef(!0),f=h.useRef(null);return h.useEffect(()=>(c.current=!0,()=>{c.current=!1}),[]),h.useEffect(()=>{if(t!==!0||!z(i)){r([]),n(!1),d(!1),f.current=null;return}const o=`${t}:${e}`;f.current!==o&&(d(!1),f.current=o);let p=!1,m=0,x=null;const N=async()=>{const v=++m;n(!0);try{const b=await K({lat:i.lat,lon:i.lng},e);if(p||v!==m)return;c.current&&r(b)}catch(b){if(console.error("[useNearbyStopsEverywhere] Failed to refresh nearby rows:",b),p||v!==m)return}finally{!p&&v===m&&c.current&&(n(!1),d(!0))}};return N(),x=setInterval(()=>void N(),ue),()=>{p=!0,x!=null&&clearInterval(x)}},[t,e,i]),{arrivalRows:l,isLoading:u,hasCompletedInitialLoad:s}}function Ie(e,t={}){const{limit:i=5}=t,l=M(),r=R(),[u,n]=h.useState([]),[s,d]=h.useState(!1),[c,f]=h.useState(!1),o=h.useRef(null);return h.useEffect(()=>{if(!e||l!==!0||!z(r)){n([]),f(!1),o.current=null;return}const p=`${e}:${i}:${l}`;o.current!==p&&(f(!1),o.current=p);let m=!1,x=0;const N=r.lat,v=r.lng;return(async()=>{const S=++x;d(!0);try{const g=await H(Number(e)),A=ce({lat:N,lon:v},g,i);if(m||S!==x)return;n(A)}catch(g){if(console.error("[useNearbyStopsForRoute] Failed to load route stops:",g),m||S!==x)return;n([])}finally{!m&&S===x&&(d(!1),f(!0))}})(),()=>{m=!0}},[l,i,e,r]),{stops:u,isLoading:s,hasCompletedInitialLoad:c}}export{Le as N,Te as a,Fe as b,Ie as u};
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.