(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[814],{5316:(e,t,r)=>{"use strict";r.d(t,{e:()=>i,m:()=>s});var n=r(2078),l=r(2553),o=r(9390);let a=(0,n.Dk)().length?(0,n.Dk)()[0]:(0,n.Wp)({apiKey:"AIzaSyBm6hyrQeqIRUs-vTr2nlc2LsrtQd1s_xg",authDomain:"transcastelvil-driver.firebaseapp.com",projectId:"transcastelvil-driver",storageBucket:"transcastelvil-driver.firebasestorage.app",messagingSenderId:"39914079991",appId:"1:39914079991:web:59e6f409c46e979b30b5f2"}),i=(0,l.xI)(a),s=(0,o.aU)(a)},9139:(e,t,r)=>{"use strict";function n(e){return e?new Intl.DateTimeFormat("es-EC",{dateStyle:"medium",timeStyle:"short"}).format(e):"Sin fecha"}function l(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return new Intl.NumberFormat("es-EC",{maximumFractionDigits:t}).format(e||0)}function o(e){if(!e)return"Sin actualizaci\xf3n";let t=Math.floor((Date.now()-e.getTime())/6e4);if(t<1)return"Hace instantes";if(t<60)return"Hace ".concat(t," min");let r=Math.floor(t/60);return"Hace ".concat(r," h")}function a(e){return!!e&&Date.now()-e.getTime()<=12e4}r.d(t,{Yq:()=>n,ZV:()=>l,om:()=>o,Of:()=>a})},9632:(e,t,r)=>{Promise.resolve().then(r.bind(r,9681)),Promise.resolve().then(r.t.bind(r,2619,23))},9681:(e,t,r)=>{"use strict";r.d(t,{LiveMap:()=>s});var n=r(5155),l=r(2115),o=r(9390),a=r(5316),i=r(9139);function s(e){let{drivers:t}=e,r=function(){let[e,t]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{var e;if(null==(e=window.google)?void 0:e.maps)return void t(!0);let r=document.getElementById("google-maps-script");if(r)return void r.addEventListener("load",()=>t(!0),{once:!0});let n=document.createElement("script");n.id="google-maps-script",n.async=!0,n.src="https://maps.googleapis.com/maps/api/js?key=".concat("AIzaSyA_Cz8BnncMwbpodA8XWNSaoEliz52kEAI"),n.onload=()=>t(!0),document.body.appendChild(n)},[]),e}(),s=(0,l.useRef)(null),c=(0,l.useRef)(null),d=(0,l.useRef)(new Map),u=(0,l.useRef)(null),[f,m]=(0,l.useState)([]);return(0,l.useEffect)(()=>{let e=(0,o.aQ)((0,o.P)((0,o.rJ)(a.m,"locations")),e=>{m(e.docs.map(e=>{var t,r,n,l,o,a,i;let s=e.data(),c=null!=(n=null==(r=s.updatedAt)||null==(t=r.toDate)?void 0:t.call(r))?n:null;return{id:e.id,driverId:null!=(l=s.driverId)?l:e.id,lat:Number(null!=(o=s.lat)?o:0),lng:Number(null!=(a=s.lng)?a:0),speedKmh:Number(null!=(i=s.speedKmh)?i:0),tripId:s.tripId,updatedAt:c}}))});return()=>e()},[]),(0,l.useEffect)(()=>{r&&s.current&&!c.current&&(c.current=new window.google.maps.Map(s.current,{center:{lat:-2.17,lng:-79.92},zoom:7,mapTypeControl:!1,streetViewControl:!1,fullscreenControl:!1,styles:[{elementType:"geometry",stylers:[{color:"#080812"}]},{elementType:"labels.text.fill",stylers:[{color:"#f0f4ff"}]},{elementType:"labels.text.stroke",stylers:[{color:"#0f0f1a"}]},{featureType:"road",elementType:"geometry",stylers:[{color:"#181825"}]},{featureType:"water",elementType:"geometry",stylers:[{color:"#0f172a"}]}]}),u.current=new window.google.maps.InfoWindow)},[r]),(0,l.useEffect)(()=>{if(!c.current||!window.google)return;let e=new window.google.maps.LatLngBounds;f.forEach(r=>{let n=t.find(e=>e.id===r.driverId);if(!n)return;let l={lat:r.lat,lng:r.lng};e.extend(l);let o=(0,i.Of)(r.updatedAt),a=function(e){let t=["#f97316","#0ea5e9","#22c55e","#eab308","#ec4899","#8b5cf6","#14b8a6","#ef4444"],r=0;for(let t=0;t<e.length;t+=1)r=(r<<5)-r+e.charCodeAt(t)|0;return t[Math.abs(r)%t.length]}(r.driverId),s={path:window.google.maps.SymbolPath.CIRCLE,scale:8,fillOpacity:1,fillColor:o?a:"#8892a4",strokeColor:"#f0f4ff",strokeWeight:2},f={text:n.name.split(" ").filter(Boolean).slice(0,2).map(e=>{var t,r;return null!=(r=null==(t=e[0])?void 0:t.toUpperCase())?r:""}).join("")||n.vehiclePlate.slice(0,2).toUpperCase()||"DR",color:"#f8fafc",fontSize:"11px",fontWeight:"700"},m=d.current.get(r.driverId);m||((m=new window.google.maps.Marker({map:c.current,position:l,icon:s,label:f,title:n.name})).addListener("click",()=>{var e,t;let r=m.__meta;null==(e=u.current)||e.setContent('<div style="min-width:200px;color:#080812">\n              <strong>'.concat(r.driver.name,"</strong><br />\n              Placa: ").concat(r.driver.vehiclePlate,"<br />\n              Velocidad: ").concat(r.location.speedKmh.toFixed(1)," km/h<br />\n              Actualizaci\xf3n: ").concat((0,i.om)(r.location.updatedAt),"\n            </div>")),null==(t=u.current)||t.open({map:c.current,anchor:m})}),d.current.set(r.driverId,m)),m.__meta={driver:n,location:r},m.setIcon(s),m.setLabel(f),m.setPosition(l)}),e.isEmpty()||c.current.fitBounds(e,64)},[t,f]),(0,n.jsx)("div",{className:"h-[420px] rounded-[16px]",ref:s})}}},e=>{e.O(0,[858,187,619,320,441,255,358],()=>e(e.s=9632)),_N_E=e.O()}]);