import{q as D,r as k,u as y,v as $,y as S,z as F}from"./chunk-ISCRPPFS.js";import{c as m,d as W}from"./chunk-GYIOPDJL.js";import{A as N,F as I,a as w,b as T,ia as E,k as O,la as v,ma as _,od as C,qa as A,u as M,va as f}from"./chunk-EBMUBP7P.js";k();v();_();W();var c=class n{static{this.COLORS={PRIMARY_BLUE:"#4285F4",ORANGE:"#FF8C00",ORANGE_BORDER:"#FF4500",WHITE:"white",BLACK:"#333",LIGHT_GRAY:"#eee"}}static{this.POLYLINE={STROKE_COLOR:n.COLORS.PRIMARY_BLUE,STROKE_OPACITY:.8,STROKE_WEIGHT:3}}static{this.MARKER={CIRCLE_SIZE:24,SPACING:4,CIRCLE_RADIUS:10,FONT_SIZE:10,FONT_WEIGHT:"bold",LABEL_COLOR:n.COLORS.WHITE,BORDER_WIDTH:2}}static{this.INFO_WINDOW={MAX_WIDTH:"300px",FONT_FAMILY:"var(--paw-font-family)",MARGIN_BOTTOM:"10px",PADDING:"5px",BORDER_BOTTOM:`1px solid ${n.COLORS.LIGHT_GRAY}`,TITLE_MARGIN:"0 0 5px 0",TITLE_COLOR:n.COLORS.BLACK,TEXT_MARGIN:"2px 0",NO_DATA_TITLE_MARGIN:"0 0 8px 0",NO_DATA_TEXT_MARGIN:"4px 0"}}static{this.MAP_BOUNDS={PADDING:{TOP:50,RIGHT:50,BOTTOM:50,LEFT:50}}}static{this.DEFAULT_LOCATION={LAT:46.1512,LNG:14.9955}}static{this.EMOJIS={START_FLAG:"\u{1F3F3}\uFE0F",LOCATION_PIN:"\u{1F4CD}"}}static getPolylineOptions(){return{strokeColor:n.POLYLINE.STROKE_COLOR,strokeOpacity:n.POLYLINE.STROKE_OPACITY,strokeWeight:n.POLYLINE.STROKE_WEIGHT}}static getDirectionsRendererOptions(){return{suppressMarkers:!0,polylineOptions:n.getPolylineOptions()}}static getMarkerLabelOptions(d=n.MARKER.LABEL_COLOR,e=n.MARKER.FONT_WEIGHT){return{color:d,fontWeight:e}}static getInfoWindowContent(d){return`
      <div style="font-family: ${n.INFO_WINDOW.FONT_FAMILY}; max-width: ${n.INFO_WINDOW.MAX_WIDTH};">
        ${d}
      </div>
    `}static getMarkerInfoContent(d,e){let t=e?`
      <p style="margin: ${n.INFO_WINDOW.TEXT_MARGIN};"><strong>Purpose:</strong> ${e.purpose||"N/A"}</p>
      <p style="margin: ${n.INFO_WINDOW.TEXT_MARGIN};"><strong>Distance:</strong> ${e.kmString||"N/A"}</p>
      <p style="margin: ${n.INFO_WINDOW.TEXT_MARGIN};"><strong>Date:</strong> ${e.dateHourFrom?new Date(e.dateHourFrom).toLocaleDateString():"N/A"}</p>
      <p style="margin: ${n.INFO_WINDOW.TEXT_MARGIN};"><strong>Post:</strong> ${e.post||"N/A"}</p>
    `:"";return`
      <div style="margin-bottom: ${n.INFO_WINDOW.MARGIN_BOTTOM}; padding: ${n.INFO_WINDOW.PADDING}; border-bottom: ${n.INFO_WINDOW.BORDER_BOTTOM};">
        <h4 style="margin: ${n.INFO_WINDOW.TITLE_MARGIN}; color: ${n.INFO_WINDOW.TITLE_COLOR};">${d}</h4>
        ${t}
      </div>
    `}static getNoDataInfoContent(){return`
      <h4 style="margin: ${n.INFO_WINDOW.NO_DATA_TITLE_MARGIN}; color: ${n.INFO_WINDOW.TITLE_COLOR};">No Travel Data Available</h4>
      <p style="margin: ${n.INFO_WINDOW.NO_DATA_TEXT_MARGIN};">No distance data found for this travel order.</p>
    `}static getMapBoundsPadding(){return n.MAP_BOUNDS.PADDING}static getDefaultLocation(){return{lat:n.DEFAULT_LOCATION.LAT,lng:n.DEFAULT_LOCATION.LNG}}static getGroupMarkerSvg(d,e,t){return`
      <svg width="${e}" height="${t}" viewBox="0 0 ${e} ${t}" fill="none" xmlns="http://www.w3.org/2000/svg">
        ${d.map((o,i)=>{let s=i*n.MARKER.CIRCLE_SIZE+i*n.MARKER.SPACING+n.MARKER.CIRCLE_SIZE/2,r=n.MARKER.CIRCLE_SIZE/2;return`<circle cx="${s}" cy="${r}" r="${n.MARKER.CIRCLE_RADIUS}" fill="${n.COLORS.ORANGE}" stroke="${n.COLORS.ORANGE_BORDER}" stroke-width="${n.MARKER.BORDER_WIDTH}"/>
                    <text x="${s}" y="${r+2}" text-anchor="middle" fill="${n.MARKER.LABEL_COLOR}" font-size="${n.MARKER.FONT_SIZE}" font-weight="${n.MARKER.FONT_WEIGHT}">${o.label}</text>`}).join("")}
      </svg>
    `}};C();$();F();var L=class{constructor(d,e,t){this.isGroupMarker=!0,this.markers=[],this.map=d,this.position=e,this.markers.push(t),this.createOverlay(),this.addClickListeners()}createOverlay(){let d=this.markers.length,e=c.MARKER.CIRCLE_SIZE,t=c.MARKER.SPACING,o=d*e+(d-1)*t,i=e,s=c.getGroupMarkerSvg(this.markers,o,i);this.overlay=new window.google.maps.Marker({position:this.position,map:this.map,icon:{url:"data:image/svg+xml;charset=UTF-8,"+encodeURIComponent(s),scaledSize:new window.google.maps.Size(o,i),anchor:new window.google.maps.Point(o/2,i/2)},title:this.markers.map(r=>r.title).join(", ")})}addMarkerToGroup(d){this.markers.push(d),this.updateOverlay()}updateOverlay(){this.overlay&&this.overlay.setMap(null),this.createOverlay(),this.addClickListeners()}addClickListeners(){this.infoWindow||(this.infoWindow=new window.google.maps.InfoWindow),this.overlay.addListener("click",()=>{let d=this.markers.map(e=>c.getMarkerInfoContent(e.title,e.distance)).join("");this.infoWindow.setContent(c.getInfoWindowContent(d)),this.infoWindow.open(this.map,this.overlay)})}getPosition(){return this.position}setMap(d){this.overlay&&this.overlay.setMap(d)}},Y=(()=>{class n{constructor(e,t){this.apiService=e,this.localeService=t,this.apiLoaded=!1,this.apiLoading=!1,this.googleApiKey="",this.apiLoadedSubject=new M(!1),this.isGoogleApiKeyValid=!0}fetchGoogleApiKey(){return O(this,null,function*(){try{let e=yield I(this.apiService.getText(D.subject.googleApiKey));return this.googleApiKey=e,e||""}catch{return""}})}loadGoogleMapsScript(e){return O(this,null,function*(){return this.apiLoaded?!0:this.apiLoading?yield I(this.apiLoadedSubject.pipe(E(t=>N(t)))):(this.apiLoading=!0,window.google&&window.google.maps?(this.apiLoaded=!0,this.apiLoading=!1,this.apiLoadedSubject.next(!0),!0):new Promise(t=>{let o=window.gm_authFailure;window.gm_authFailure=()=>{this.isGoogleApiKeyValid=!1,o&&typeof o=="function"&&o()};let i=document.createElement("script"),s=e?`key=${encodeURIComponent(e)}`:"",r=this.localeService.getGoogleMapsLanguageCode();i.src=`https://maps.googleapis.com/maps/api/js?${s}&libraries=drawing,geometry,places&language=${r}&v=weekly`,i.async=!0,i.defer=!0,i.onload=()=>{this.apiLoaded=!0,this.apiLoading=!1,this.apiLoadedSubject.next(!0),t(!0)},i.onerror=()=>{this.apiLoading=!1,t(!1)},document.head.appendChild(i)}))})}loadGoogleMaps(){return O(this,null,function*(){if(this.apiLoaded)return;let e=yield this.fetchGoogleApiKey();yield this.loadGoogleMapsScript(e),this.validateApiKey()})}isApiKeyValid(){return this.isGoogleApiKeyValid}checkIfLoaded(e){return O(this,null,function*(){return this.apiLoaded?!0:yield this.loadGoogleMapsScript(e)})}calculateDistance(e,t){return O(this,null,function*(){return new Promise(o=>{let i=new window.google.maps.DirectionsService,s={origin:e,destination:t,travelMode:window.google.maps.DirectionsTravelMode.DRIVING};i.route(s,(r,a)=>{if(a===window.google.maps.DirectionsStatus.OK){let l=r.routes[0].legs[0];if(l){let g=l.distance.text,u=m.strToNum(g);o(u??0)}else o(0)}else o(0)})})})}validateApiKey(){return new Promise(e=>{try{let t=new window.google.maps.DirectionsService,o={origin:"0,0",destination:"1,1",travelMode:window.google.maps.DirectionsTravelMode.DRIVING};t.route(o,(i,s)=>{[window.google.maps.DirectionsStatus.REQUEST_DENIED,window.google.maps.DirectionsStatus.INVALID_REQUEST,window.google.maps.DirectionsStatus.OVER_QUERY_LIMIT].includes(s)?(this.isGoogleApiKeyValid=!1,e(!1)):(this.isGoogleApiKeyValid=!0,e(!0))})}catch{this.isGoogleApiKeyValid=!1,e(!1)}})}createMap(e,t){return!e||!window.google?.maps?null:new window.google.maps.Map(e,t)}calculateAndDisplayRouteWithHeader(e,t,o,i,s){if(!t&&i.length===0)return;let r=new window.google.maps.DirectionsService,a=new window.google.maps.DirectionsRenderer(c.getDirectionsRendererOptions());a.setMap(e),e.directionsRenderer=a;let l={origin:t||i[0],destination:o||i[i.length-1],travelMode:window.google.maps.TravelMode.DRIVING,optimizeWaypoints:!1};i.length>0&&(l.waypoints=i.map(g=>({location:g,stopover:!0}))),r.route(l,(g,u)=>{if(u==="OK"){a.setDirections(g),this.addMarkersToRouteWithHeader(e,g.routes[0],s,t,o);let h=new window.google.maps.LatLngBounds;g.routes[0].legs.forEach(p=>{h.extend(p.start_location),h.extend(p.end_location)}),e.fitBounds(h,c.getMapBoundsPadding()),setTimeout(()=>{window.google.maps.event.trigger(e,"resize")},100)}else this.fallbackToIndividualGeocoding(e,[t,...i,o].filter(Boolean),s)})}calculateAndDisplayRoute(e,t,o){if(t.length===0)return;let i=new window.google.maps.DirectionsService,s=new window.google.maps.DirectionsRenderer(c.getDirectionsRendererOptions());s.setMap(e),e.directionsRenderer=s;let r={origin:t[0],destination:t[t.length-1],travelMode:window.google.maps.TravelMode.DRIVING,optimizeWaypoints:!1};t.length>2&&(r.waypoints=t.slice(1,-1).map(a=>({location:a,stopover:!0}))),i.route(r,(a,l)=>{if(l==="OK"){s.setDirections(a),this.addMarkersToRoute(e,a.routes[0],o);let g=new window.google.maps.LatLngBounds;a.routes[0].legs.forEach(u=>{g.extend(u.start_location),g.extend(u.end_location)}),e.fitBounds(g,c.getMapBoundsPadding()),setTimeout(()=>{window.google.maps.event.trigger(e,"resize")},100)}else this.fallbackToIndividualGeocoding(e,t,o)})}addMarkersToRouteWithHeader(e,t,o,i,s){if(t.legs.length>0){let r=t.legs[0];this.addMarker(e,r.start_location,i||"Start Location",c.EMOJIS.START_FLAG,null,!0)}if(t.legs.forEach((r,a)=>{if(a<o.length){let l=o[a]?.ordinalNumber||a+1;this.addMarker(e,r.end_location,o[a]?.distance?.displayNode||o[a]?.distance?.node||`Waypoint ${l}`,`${l}`,o[a]?.distance,!1)}}),t.legs.length>0&&s){let r=t.legs[t.legs.length-1],l=(o.length>0?o[o.length-1]?.ordinalNumber||o.length:0)+1;this.addMarker(e,r.end_location,s||"End Location",`${l}`,null,!1)}}addMarkersToRoute(e,t,o){if(t.legs.length>0){let i=t.legs[0];this.addMarker(e,i.start_location,o[0]?.distance?.displayNode||o[0]?.distance?.node||"Start",c.EMOJIS.START_FLAG,o[0]?.distance,!0)}t.legs.forEach((i,s)=>{s<o.length-1&&this.addMarker(e,i.end_location,o[s+1]?.distance?.displayNode||o[s+1]?.distance?.node||`Waypoint ${s+1}`,`${s+1}`,o[s+1]?.distance,!1)})}addMarker(e,t,o,i,s,r=!1){let a=typeof t.lat=="function"?t.lat():t.lat,l=typeof t.lng=="function"?t.lng():t.lng,g=null;if(e.markers&&e.markers.length>0&&e.markers.forEach(h=>{if(h.isGroupMarker){let p=h.getPosition();if(p){let R=typeof p.lat=="function"?p.lat():p.lat,G=typeof p.lng=="function"?p.lng():p.lng;Math.abs(a-R)<1e-5&&Math.abs(l-G)<1e-5&&(g=h)}}}),g)return g.addMarkerToGroup({title:o,label:i,distance:s,isFirstPoint:r}),g;let u=new L(e,t,{title:o,label:i,distance:s,isFirstPoint:r});return e.markers||(e.markers=[]),e.markers.push(u),u}fallbackToIndividualGeocoding(e,t,o){let i=new window.google.maps.LatLngBounds,s=[],r=0;t.forEach((a,l)=>{new window.google.maps.Geocoder().geocode({address:a},(u,h)=>{if(r++,h==="OK"&&u[0]){let p=u[0].geometry.location;i.extend(p);let R=this.addMarker(e,p,o[l]?.distance?.displayNode||o[l]?.distance?.node||a,l===0?c.EMOJIS.START_FLAG:`${l}`,o[l]?.distance,l===0);s.push(R)}r===t.length&&(this.drawRouteLines(e,s,[]),s.length>0&&e.fitBounds(i,c.getMapBoundsPadding()))})})}drawRouteLines(e,t,o){for(let i=0;i<t.length-1;i++){let s=new window.google.maps.Polyline(T(w({path:[t[i].getPosition(),t[i+1].getPosition()],geodesic:!0},c.getPolylineOptions()),{map:e}));o.push(s)}e.polylines||(e.polylines=[]),e.polylines.push(...o)}clearMap(e){if(!e)return;(e.markers||[]).forEach(i=>{i.isGroupMarker,i.setMap(null)}),(e.polylines||[]).forEach(i=>{i.setMap(null)}),e.directionsRenderer&&e.directionsRenderer.setMap(null),e.overlayMapTypes?.clear(),e.markers=[],e.polylines=[],e.directionsRenderer=null}addDefaultMarker(e){if(!e)return;let t=c.getDefaultLocation(),o=new window.google.maps.Marker({position:t,map:e,title:"Default Location",label:w({text:c.EMOJIS.LOCATION_PIN},c.getMarkerLabelOptions())}),i=new window.google.maps.InfoWindow({content:c.getInfoWindowContent(c.getNoDataInfoContent())});o.addListener("click",()=>{i.open(e,o)})}reverseGeocode(e,t){return O(this,null,function*(){if(!window.google?.maps)throw new Error("Google Maps not loaded");return new Promise((o,i)=>{let s=new window.google.maps.Geocoder,r={lat:e,lng:t};s.geocode({location:r},(a,l)=>{l==="OK"&&a[0]?o(a[0].formatted_address):i(new Error(`Geocoding failed: ${l}`))})})})}static{this.\u0275fac=function(t){return new(t||n)(f(y),f(S))}}static{this.\u0275prov=A({token:n,factory:n.\u0275fac,providedIn:"root"})}}return n})();export{Y as a};
