1import{u as f,j as e,q as Ss,aj as V,L as Ze,M as Te,O as Ae,dV as q,dW as Be,R as ks,E as oe,au as ie,ay as _,av as Oe,cX as Ge,co as Ls,cL as Ms,ag as ce,dX as Es,dY as zs,dZ as Ps}from"./vendor-ui-fc56ca80.js";import{r}from"./vendor-react-f9ccc48d.js";import{h as Ds,bC as We,I as Ue,B as u,R as $,t as Is,v as Fs,w as $s,x as Rs,y as Zs,z as Ve,F as Ts}from"./index-90016d22.js";import{p as qe}from"./personService-8722b083.js";import{c as As,G as Bs,d as _e,I as Ke,e as Os,C as Gs,D as Ws,f as Us,g as Vs,S as qs}from"./vendor-maps-c713695f.js";import{g as _s}from"./google-maps-9a1a43c3.js";import"./vendor-firebase-a557f106.js";import"./vendor-utils-323b9898.js";import"./vendor-charts-9af8b7c0.js";import"./familyService-e128c442.js";const Ks={width:"100%",height:"calc(100vh - 64px)"},Hs={lat:-36.8261,lng:-73.0498},Xs={fullscreenControl:!0,streetViewControl:!0,mapTypeControl:!0,zoomControl:!0,mapTypeId:"roadmap",styles:[{featureType:"poi",elementType:"labels",stylers:[{visibility:"off"}]}]},Ys=["places","drawing","geometry"];function ia(){var Fe,$e;const{isLoaded:b,loadError:He}=As({id:"google-maps-script",googleMapsApiKey:"AIzaSyB3yYTEQgOPqbQuXgSwW0naJ0N0cwjOiGY",libraries:Ys}),{userData:j}=Ds(),[,de]=r.useState(!1),[Xe,Ye]=r.useState([]),[g,K]=r.useState([]),[Qe,H]=r.useState([]),[h,X]=r.useState(null),[C,Y]=r.useState(""),[Je]=r.useState(12),[c,me]=r.useState(null),[es,Q]=r.useState(!1),[ue,he]=r.useState(null),[xe,ge]=r.useState(null),[J,fe]=r.useState(!1),[pe,R]=r.useState(!1),[je,Ne]=r.useState([]),[ss,we]=r.useState(!1),[p,ye]=r.useState([]),[w,k]=r.useState(null),[Z,T]=r.useState(!1),[ee,as]=r.useState("polygon"),[,ts]=r.useState(null),[d,se]=r.useState([]),[E,ve]=r.useState(!1),[L,be]=r.useState([]),[Ce,ae]=r.useState(!1),[,ns]=r.useState({totalLocations:0,totalPersons:0,averagePersonsPerLocation:0,zonesCount:0,personsByZone:{},personsByStatus:{},maxDistance:0,averageDistance:0}),[y]=r.useState({status:"",zone:"",family:"",minMembers:0,maxMembers:100,searchTerm:""}),[,ls]=r.useState("locations"),[rs,A]=r.useState(!1),[B,Se]=r.useState(""),[S,os]=r.useState("#FF0000"),[O,ke]=r.useState(!1),[z,te]=r.useState(!1),[M,P]=r.useState(null),[G,D]=r.useState(!1),[I,Le]=r.useState("DRIVING"),[ne,F]=r.useState(null);r.useEffect(()=>{b&&(j!=null&&j.churchId)&&Ee()},[b,j==null?void 0:j.churchId]),r.useEffect(()=>{g.length>0&&is()},[g,p]);const is=()=>{const s=g.length,a=g.reduce((N,re)=>N+re.persons.length,0),t=s>0?a/s:0,n=p.length,l={};p.forEach(N=>{l[N.name]=0}),g.forEach(N=>{N.zone&&(l[N.zone]=(l[N.zone]||0)+N.persons.length)});const i={};g.forEach(N=>{N.persons.forEach(re=>{const Re=re.estado||"Sin estado";i[Re]=(i[Re]||0)+1})});let o=0,x=0,m=0;L.length>0&&L.forEach(N=>{N.distance>o&&(o=N.distance),x+=N.distance,m++});const v=m>0?x/m:0;ns({totalLocations:s,totalPersons:a,averagePersonsPerLocation:t,zonesCount:n,personsByZone:l,personsByStatus:i,maxDistance:o,averageDistance:v})},cs=s=>{ts(s)},ds=s=>{const a=s.getPath(),t=[];for(let l=0;l<a.getLength();l++){const i=a.getAt(l);t.push({lat:i.lat(),lng:i.lng()})}A(!0);const n={id:`zone-${Date.now()}`,name:"",color:S,points:t,type:"polygon"};k(n),s.setMap(null),T(!1)},ms=s=>{const a=s.getCenter(),t=s.getRadius();if(a){A(!0);const n={id:`zone-${Date.now()}`,name:"",color:S,points:[],center:{lat:a.lat(),lng:a.lng()},radius:t,type:"circle"};k(n),s.setMap(null),T(!1)}},us=()=>{if(w&&B.trim()!==""){const s={...w,name:B,color:S};ye([...p,s]);const a=[...g];a.forEach((t,n)=>{hs(t,s)&&(a[n]={...t,zone:s.name})}),K(a),H(a),A(!1),Se(""),k(null),f.success("Zona creada correctamente")}},hs=(s,a)=>a.type==="circle"&&a.center&&a.radius?xs(s.lat,s.lng,a.center.lat,a.center.lng)<=a.radius:a.type==="polygon"?gs({lat:s.lat,lng:s.lng},a.points):!1,xs=(s,a,t,n)=>{const i=W(t-s),o=W(n-a),x=Math.sin(i/2)*Math.sin(i/2)+Math.cos(W(s))*Math.cos(W(t))*Math.sin(o/2)*Math.sin(o/2);return 6371e3*(2*Math.atan2(Math.sqrt(x),Math.sqrt(1-x)))},W=s=>s*(Math.PI/180),gs=(s,a)=>{let t=!1;for(let n=0,l=a.length-1;n<a.length;l=n++){const i=a[n].lat,o=a[n].lng,x=a[l].lat,m=a[l].lng;o>s.lng!=m>s.lng&&s.lat<(x-i)*(s.lng-o)/(m-o)+i&&(t=!t)}return t},U=s=>{if(d.find(l=>l.location.lat===s.lat&&l.location.lng===s.lng)){f.info("Esta ubicación ya está en la ruta");return}const t={id:We(),location:s,order:d.length+1,visited:!1},n=[...d,t];if(se(n),c&&n.length>0){const l=new google.maps.LatLngBounds;
1n.forEach(i=>{l.extend({lat:i.location.lat,lng:i.location.lng})}),c.fitBounds(l),n.length===1&&c.setZoom(15)}R(!1),ls("route"),te(!0),f.success("Ubicación añadida a la ruta")},fs=s=>{const a=d.filter(t=>!(t.location.lat===s.lat&&t.location.lng===s.lng));if(a.forEach((t,n)=>{t.order=n+1}),se(a),c&&a.length>0){const t=new google.maps.LatLngBounds;a.forEach(n=>{t.extend({lat:n.location.lat,lng:n.location.lng})}),c.fitBounds(t)}else if(c&&g.length>0){const t=new google.maps.LatLngBounds;g.forEach(n=>{t.extend({lat:n.lat,lng:n.lng})}),c.fitBounds(t)}f.success("Ubicación eliminada de la ruta")},ps=async()=>{if(d.length<2){f.error("Se necesitan al menos 2 ubicaciones para calcular distancias");return}ae(!0);try{if(!b||!google||!google.maps){f.error("La API de Google Maps no está cargada"),ae(!1);return}const s=new google.maps.DistanceMatrixService,a=d.map(o=>({lat:o.location.lat,lng:o.location.lng})),t=[...a],n=I==="DRIVING"?google.maps.TravelMode.DRIVING:google.maps.TravelMode.WALKING,l=await new Promise((o,x)=>{s.getDistanceMatrix({origins:a,destinations:t,travelMode:n,unitSystem:google.maps.UnitSystem.METRIC},(m,v)=>{v===google.maps.DistanceMatrixStatus.OK&&m?o(m):x(new Error(`Error en Distance Matrix: ${v}`))})}),i=[];if(l&&l.rows){for(let o=0;o<d.length;o++)if(l.rows[o]&&l.rows[o].elements){for(let x=0;x<d.length;x++)if(o!==x){const m=l.rows[o].elements[x];m&&m.status==="OK"&&m.distance&&m.duration&&i.push({origin:d[o].location,destination:d[x].location,distance:m.distance.value,duration:m.duration.value})}}}if(be(i),i.length>0){const o=i.reduce((x,m)=>x+m.distance,0)/(d.length-1);f.success(`Distancias calculadas. Distancia total aproximada: ${(o/1e3).toFixed(2)} km`)}else f.warning("No se pudieron calcular distancias entre los puntos seleccionados")}catch(s){console.error("Error calculando distancias:",s),f.error("Error al calcular distancias. Asegúrate de que la API de Distance Matrix esté habilitada.")}finally{ae(!1)}},Me=r.useCallback(()=>{if(!b||!c||d.length<2)return;const s=new google.maps.DirectionsService,a=d.slice(1,d.length-1).map(l=>({location:new google.maps.LatLng(l.location.lat,l.location.lng),stopover:!0})),t=new google.maps.LatLng(d[0].location.lat,d[0].location.lng),n=new google.maps.LatLng(d[d.length-1].location.lat,d[d.length-1].location.lng);try{s.route({origin:t,destination:n,waypoints:a,optimizeWaypoints:!1,travelMode:I},(l,i)=>{i===google.maps.DirectionsStatus.OK?F(l):(console.error(`Error al calcular la ruta: ${i}`),i==="REQUEST_DENIED"?sessionStorage.getItem("directions_api_warning_shown")||(f.warning("El servicio de direcciones no está habilitado en tu API de Google Maps. Se mostrarán lÃneas rectas entre los puntos."),sessionStorage.setItem("directions_api_warning_shown","true")):f.error("No se pudo calcular la ruta. Mostrando lÃnea recta."),F(null))})}catch(l){console.error("Error al intentar calcular la ruta:",l),F(null)}},[b,c,d,I]);r.useEffect(()=>{if(E&&d.length>=2)try{Me()}catch(s){console.error("Error en el cálculo de ruta:",s),F(null)}else F(null)},[E,d,I,Me]);const js=()=>{if(d.length===0){f.info("No hay puntos en la ruta para limpiar");return}se([]),be([]),F(null),ve(!1),f.success("Ruta limpiada correctamente")},Ee=async()=>{if(j!=null&&j.churchId)try{de(!0);const s=await qe.getAll(j.churchId);Ye(s);const a=new Map;s.forEach(o=>{if(o.address&&typeof o.address=="object")try{const x=`${o.address.street||""} ${o.address.streetNumber||""}, ${o.address.level2||""}`,m=a.get(x)||[];a.set(x,[...m,o])}catch(x){console.error("Error procesando dirección:",x,o)}});const t=[],n={lat:-35.675147,lng:-71.542969},l=5;let i=null;b&&google&&google.maps&&(i=new google.maps.LatLngBounds);for(const[o,x]of a.entries()){const m=x[0];if(m.address&&typeof m.address=="object"&&"lat"in m.address&&"lng"in m.address&&typeof m.address.lat=="number"&&typeof m.address.lng=="number"){const v={id:We(),lat:m.address.lat,lng:m.address.lng,persons:x,address:o};t.push(v),i&&i.extend({lat:v.lat,lng:v.lng})}}if(K(t),H(t),t.length>0&&c&&i&&!i.isEmpty())try{c.fitBounds(i),google.maps.event.addListenerOnce(c,"bounds_changed",()=>{if(c){const o=c.getZoom();o&&o>12?c.setZoom(12):o&&o<5&&c.setZoom(5)}})}catch(o){console.error("Error al ajustar el mapa a las ubicaciones:",o),c&&(c.setCenter(n),c.setZoom(l))}else c&&(c.setCenter(n),c.setZoom(l))}catch(s){console.error("Error loading persons:",s),f.error("Error al cargar las personas")}finally{de(!1)}},Ns=async()=>
1{if(j!=null&&j.churchId)try{fe(!0);let s=!1;for(const a of Xe)if(a.address&&!("lat"in a.address)&&!("lng"in a.address)){const t=`${a.address.street} ${a.address.streetNumber}, ${a.address.level2}`,n=await _s(t,a.address.countryCode);n&&(await qe.update(j.churchId,a.id,{...a,address:{...a.address,lat:n.lat,lng:n.lng}}),s=!0)}s?(await Ee(),f.success("Ubicaciones actualizadas correctamente")):f.info("No hay ubicaciones pendientes de actualizar")}catch(s){console.error("Error updating locations:",s),f.error("Error al actualizar las ubicaciones")}finally{fe(!1)}},ze=async s=>{try{const a=`${s.address} 2 3Personas: 4${s.persons.map(t=>`${t.nombres} ${t.paterno}${t.telefono?` - ${t.telefono}`:""}`).join(` 5`)}`;await navigator.clipboard.writeText(a),he(s.address),setTimeout(()=>he(null),2e3),f.success("Información copiada al portapapeles")}catch{f.error("Error al copiar la información")}},Pe=async s=>{try{const a=`https://www.google.com/maps/search/?api=1&query=${s.lat},${s.lng}`;await navigator.clipboard.writeText(a),ge(a),setTimeout(()=>ge(null),2e3),f.success("URL del mapa copiada al portapapeles")}catch{f.error("Error al copiar la URL")}};r.useEffect(()=>{if(C.length>0){we(!0);const s=setTimeout(()=>{const a=g.filter(t=>{const n=t.address.toLowerCase().includes(C.toLowerCase()),l=t.persons.some(i=>`${i.nombres} ${i.paterno}`.toLowerCase().includes(C.toLowerCase())||i.telefono&&i.telefono.includes(C));return n||l});Ne(a),we(!1)},300);return()=>clearTimeout(s)}else Ne([])},[C,g]),r.useEffect(()=>{let s=[...g];if(y.status&&(s=s.filter(a=>a.persons.some(t=>t.estado===y.status))),y.zone&&(s=s.filter(a=>a.zone===y.zone)),(y.minMembers>0||y.maxMembers<100)&&(s=s.filter(a=>{const t=a.persons.length;return t>=y.minMembers&&t<=y.maxMembers})),y.searchTerm){const a=y.searchTerm.toLowerCase();s=s.filter(t=>{const n=t.address.toLowerCase().includes(a),l=t.persons.some(i=>`${i.nombres} ${i.paterno}`.toLowerCase().includes(a));return n||l})}H(s)},[g,y]);const De=(s,a=!1)=>{X(s),R(!0),a&&(c==null||c.panTo({lat:s.lat,lng:s.lng}),c==null||c.setZoom(16))},ws=r.useCallback(s=>{if(!s)return;me(s);const a={lat:-35.675147,lng:-71.542969},t=5;s.setCenter(a),s.setZoom(t),g.length>0&&le(s,g)},[g]),le=r.useCallback((s,a)=>{if(!(!s||a.length===0))try{const t=new google.maps.LatLngBounds;let n=!1;a.forEach(l=>{typeof l.lat=="number"&&typeof l.lng=="number"&&(t.extend({lat:l.lat,lng:l.lng}),n=!0)}),n&&(s.fitBounds(t),google.maps.event.addListenerOnce(s,"bounds_changed",()=>{if(!s)return;const l=s.getZoom();l&&l>12?s.setZoom(12):l&&l<5&&s.setZoom(5)}))}catch(t){console.error("Error al ajustar el mapa a las ubicaciones:",t)}},[]);r.useEffect(()=>{c&&g.length>0&&le(c,g)},[c,g,le]);const ys=r.useCallback(()=>{me(null)},[]),Ie=s=>{as(s),T(!0)},vs=()=>{T(!1)},bs=s=>{if(confirm("¿Estás seguro de que deseas eliminar esta zona?")){ye(p.filter(t=>t.id!==s));const a=p.find(t=>t.id===s);if(a){const t=g.map(n=>n.zone===a.name?{...n,zone:void 0}:n);K(t)}}},Cs=s=>{const a=p.find(l=>l.id===s);if(!a)return[];const t=g.filter(l=>l.zone===a.name);let n=[];return t.forEach(l=>{n=[...n,...l.persons]}),n};return r.useEffect(()=>{if(!b||!c)return;const s=c.addListener("click",()=>{G&&(D(!1),P(null))});return()=>{c&&google.maps.event.removeListener(s)}},[b,c,G]),He?e.jsx("div",{children:"Error al cargar el mapa"}):e.jsxs("div",{className:"relative h-[calc(100vh-64px)] overflow-hidden",children:[e.jsxs("div",{className:"absolute top-0 left-0 right-0 z-10 bg-white/90 backdrop-blur-sm p-3 shadow-sm flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(Ss,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-500"}),e.jsx(Ue,{placeholder:"Buscar por dirección, nombre o teléfono...",className:"pl-10 pr-10",value:C,onChange:s=>Y(s.target.value)}),C.length>0&&e.jsx(u,{variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 transform -translate-y-1/2 h-6 w-6",onClick:()=>Y(""),children:e.jsx(V,{className:"h-4 w-4"})}),C.length>0&&e.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 bg-white shadow-lg rounded-md max-h-[300px] overflow-y-auto z-20 border",children:ss?e.jsxs("div",{className:"p-3 text-sm text-gray-500 flex items-center justify-center",children:[e.jsx(Ze,{className:"h-4 w-4 animate-spin"}),"Buscando..."]}):je.length>0?je.map(s=>{var a,t;return e.jsx("div",{className:"p-3 hover:bg-gray-100 cursor-pointer border-b last:border-b-0 transition-colors",onClick:()=>{De(s,!0),Y("")},children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Te,{className:"h-5 w-5 text-primary mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium",children:s.address}),e.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[e.jsxs($,{variant:"outline",className:"flex items-center gap-1",children:[e.jsx(Ae,{className:"h-3 w-3"}),s.persons.length," personas"]}),s.zone&&e.jsxs($,{variant:"outline",className:"flex items-center gap-1",style:{backgroundColor:((a=p.find(n=>n.name===s.zone))==null?void 0:a.color)+"20",borderColor:(t=p.find(n=>n.name===s.zone))==null?void 0:t.color},children:[e.jsx(q,{className:"h-3 w-3"}),s.zone]})]}),s.persons.length>0&&e.jsx("p",{className:"text-xs text-gray-500 mt-1 truncate",children:s.persons.map(n=>`${n.nombres} ${n.paterno}`).join(", ")})]})]})},`search-${s.lat}-${s.lng}`)}):e.jsxs("div",{className:"p-3 text-sm text-gray-500",children:['No se encontraron resultados para "',C,'"']})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>ke(!O),className:O?"bg-primary text-white hover:bg-primary/90":"",children:[e.jsx(q,{className:"h-4 w-4 mr-2"}),"Zonas"]}),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>te(!z),className:z?"bg-primary text-white hover:bg-primary/90":"",children:[e.jsx(Be,{className:"h-4 w-4 mr-2"}),"Ruta"]}),e.jsxs(u,{variant:"outline",size:"sm",onClick:Ns,disabled:J,children:[e.jsx(ks,{className:`mr-2 h-4 w-4 ${J?"animate-spin":""}`}),J?"Actualizando...":"Actualizar"]})]})]}),e.jsx("div",{className:"h-full w-full",children:b?e.jsxs(Bs,{mapContainerStyle:Ks,center:Hs,zoom:Je,options:Xs,onLoad:ws,onUnmount:ys,children:[Qe.map((s,a)=>{var t;return e.jsx(_e,{position:{lat:s.lat,lng:s.lng},onClick:()=>{z?U(s):De(s,!0)},onMouseOver:()=>{G||P(s)},onMouseOut:()=>{G||P(null)},icon:{path:google.maps.SymbolPath.CIRCLE,fillColor:s.zone&&((t=p.find(n=>n.name===s.zone))==null?void 0:t.color)||"#3B82F6",fillOpacity:.7,strokeWeight:1,strokeColor:"#FFFFFF",scale:6}},`location-marker-${a}-${s.lat.toFixed(6)}-${s.lng.toFixed(6)}`)}),M&&e.jsx(Ke,{position:{lat:M.lat,lng:M.lng},options:{pixelOffset:new google.maps.Size(0,-30),disableAutoPan:!0},onCloseClick:()=>{P(null),D(!1)},children:e.jsxs("div",{className:"max-w-xs",onClick:()=>D(!0),onMouseOver:()=>D(!0),children:[e.jsx("h3",{className:"font-medium mb-1 text-sm",children:M.address}),e.jsxs("p",{className:"text-xs text-gray-600 mb-2",children:[M.persons.length," personas"]}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsxs(u,{size:"sm",variant:"outline",className:"text-xs py-1 h-
57",onClick:s=>{s.stopPropagation(),X(M),R(!0),P(null),D(!1)},children:[e.jsx(oe,{className:"h-3 w-3 mr-1"}),"Ver detalles"]}),e.jsxs(u,{size:"sm",variant:"default",className:"text-xs py-1 h-7 bg-primary hover:bg-primary/90",onClick:s=>{s.stopPropagation(),U(M),P(null),D(!1)},children:[e.jsx(ie,{className:"h-3 w-3 mr-1"}),"Añadir a ruta"]})]})]})}),O&&p.map(s=>s.type==="polygon"?e.jsx(Os,{paths:s.points,options:{fillColor:s.color,fillOpacity:.3,strokeColor:s.color,strokeWeight:2,clickable:!0,editable:(w==null?void 0:w.id)===s.id},onClick:()=>k(s)},s.id):e.jsx(Gs,{center:s.center,radius:s.radius,options:{fillColor:s.color,fillOpacity:.3,strokeColor:s.color,strokeWeight:2,clickable:!0,editable:(w==null?void 0:w.id)===s.id},onClick:()=>k(s)},s.id)),Z&&e.jsx(Ws,{onLoad:cs,options:{drawingMode:ee==="polygon"?google.maps.drawing.OverlayType.POLYGON:google.maps.drawing.OverlayType.CIRCLE,drawingControl:!1,polygonOptions:{fillColor:S,fillOpacity:.3,strokeColor:S,strokeWeight:2,clickable:!0,editable:!0,zIndex:1},circleOptions:{fillColor:S,fillOpacity:.3,strokeColor:S,strokeWeight:2,clickable:!0,editable:!0,zIndex:1}},onPolygonComplete:ds,onCircleComplete:ms}),z&&E&&d.length>1&&e.jsx(e.Fragment,{children:ne?e.jsx(Us,{directions:ne,options:{suppressMarkers:!0,polylineOptions:{strokeColor:"#3B82F6",strokeWeight:4,strokeOpacity:.8}}}):e.jsx(Vs,{path:d.map(s=>({lat:s.location.lat,lng:s.location.lng})),options:{strokeColor:"#3B82F6",strokeWeight:3,strokeOpacity:.8}})}),z&&d.map(s=>e.jsx(_e,{position:{lat:s.location.lat,lng:s.location.lng},label:{text:s.order.toString(),color:"white",fontWeight:"bold",fontSize:"14px"},icon:{path:google.maps.SymbolPath.CIRCLE,fillColor:"#3B82F6",fillOpacity:1,strokeWeight:2,strokeColor:"#FFFFFF",scale:10}},`route-marker-${s.id}`)),h&&!pe&&e.jsx(Ke,{position:{lat:h.lat,lng:h.lng},onCloseClick:()=>X(null),children:e.jsxs("div",{className:"max-w-xs",children:[e.jsx("h3",{className:"font-medium",children:h.address}),e.jsxs("p",{className:"text-sm text-gray-600 mb-2",children:[h.persons.length," personas"]}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsxs(u,{size:"sm",variant:"outline",className:"flex-1",onClick:()=>{Q(!0)},children:[e.jsx(oe,{className:"h-4 w-4 mr-2"}),"Street View"]}),e.jsxs(u,{size:"sm",variant:"default",className:"flex-1 bg-primary hover:bg-primary/90",onClick:()=>U(h),children:[e.jsx(ie,{className:"h-4 w-4 mr-2"}),"Añadir a ruta"]})]}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsxs(u,{size:"sm",variant:"outline",className:"flex-1",onClick:()=>ze(h),children:[ue===h.address?e.jsx(_,{className:"h-4 w-4 mr-2 text-green-500"}):e.jsx(Oe,{className:"h-4 w-4 mr-2"}),"Copiar dirección"]}),e.jsxs(u,{size:"sm",variant:"outline",className:"flex-1",onClick:()=>Pe(h),children:[xe===`https://www.google.com/maps/search/?api=1&query=${h.lat},${h.lng}`?e.jsx(_,{className:"h-4 w-4 mr-2 text-green-500"}):e.jsx(Ge,{className:"h-4 w-4 mr-2"}),"Abrir en Maps"]})]})]})}),es&&h&&e.jsx(qs,{options:{position:{lat:h.lat,lng:h.lng},visible:!0,enableCloseButton:!0,addressControl:!0},onCloseclick:()=>Q(!1)})]}):e.jsx("div",{className:"flex justify-center items-center h-full",children:e.jsx(Ze,{className:"h-8 w-8 animate-spin text-gray-500"})})}),h&&pe&&e.jsx("div",{className:"absolute top-[72px] right-0 bottom-0 w-[400px] bg-white shadow-lg z-20 overflow-y-auto transition-all animate-in slide-in-from-right",children:e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h2",{className:"text-lg font-medium",children:"Detalles de ubicación"}),e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>R(!1),children:e.jsx(V,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-slate-50 p-3 rounded-lg border",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Te,{className:"h-5 w-5 text-primary mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium",children:h.address}),e.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[e.jsxs($,{variant:"outline",className:"flex items-center gap-1",children:[e.jsx(Ae,{className:"h-3 w-3"}),h.persons.length," personas"]}),h.zone&&e.jsxs($,{variant:"outline",className:"flex items-center gap-1",style:{backgroundColor:((Fe=p.find(s=>s.name===h.zone))==null?void 0:Fe.color)+"20",borderColor:($e=p.find(s=>s.name===h.zone))==null?void 0:$e.color},children:[e.jsx(q,{className:"h-3 w-3"}),h.zone]})]})]})]}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsxs(u,{size:"sm",variant:"outline",className:"flex-1",onClick:()=>{Q(!0)},children:[e.jsx(oe,{className:"h-4 w-4 mr-2"}),"Street View"]}),e.jsxs(u,{size:"sm",variant:"default",className:"flex-1 bg-primary hover:bg-primary/90",onClick:()=>U(h),children:[e.jsx(ie,{className:"h-4 w-4 mr-2"}),"Añadir a ruta"]})]}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsxs(u,{size:"sm",variant:"outline",className:"flex-1",onClick:()=>ze(h),children:[ue===h.address?e.jsx(_,{className:"h-4 w-4 mr-2 text-green-500"}):e.jsx(Oe,{className:"h-4 w-4 mr-2"}),"Copiar dirección"]}),e.jsxs(u,{size:"sm",variant:"outline",className:"flex-1",onClick:()=>Pe(h),children:[xe===`https://www.google.com/maps/search/?api=1&query=${h.lat},${h.lng}`?e.jsx(_,{className:"h-4 w-4 mr-2 text-green-500"}):e.jsx(Ge,{className:"h-4 w-4 mr-2"}),"Abrir en Maps"]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium",children:"Personas en esta ubicación"}),e.jsx("div",{className:"space-y-3",children:h.persons.map(s=>e.jsxs("div",{className:"p-3 border rounded-md",children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium",children:[s.nombres," ",s.paterno]}),s.estado&&e.jsx($,{variant:"outline",className:"mt-1",children:s.estado})]}),s.telefono&&e.jsxs("a",{href:`tel:${s.telefono}`,className:"text-primary hover:text-primary/80 flex items-center gap-1",children:[e.jsx(Ls,{className:"h-4 w-4"}),e.jsx("span",{children:s.telefono})]})]}),s.email&&e.jsx("p",{className:"text-sm text-gray-600 mt-2",children:s.email})]},s.id))})]})]})]})}),O&&e.jsx("div",{className:"absolute top-[72px] right-0 bottom-0 w-[350px] bg-white shadow-lg z-20 overflow-y-auto transition-transform",children:e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h2",{className:"text-lg font-medium",children:"Zonas"}),e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>ke(!1),children:e.jsx(V,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(u,{variant:Z&&ee==="polygon"?"default":"outline",size:"sm",onClick:()=>Ie("polygon"),className:"flex-1",children:[e.jsx(q,{className:"h-4 w-4 mr-2"}),"Dibujar PolÃgono"]}),e.jsxs(u,{variant:Z&&ee==="circle"?"default":"outline",size:"sm",onClick:()=>Ie("circle"),className:"flex-1",children:[e.jsx(Ms,{className:"h-4 w-4 mr-2"}),"Dibujar CÃrculo"]})]}),Z&&e.jsxs("div",{className:"bg-blue-50 p-3 rounded-md text-sm",children:[e.jsx("p",{className:"font-medium text-blue-800 mb-1",children:"Modo dibujo activo"}),e.jsx("p",{className:"text-blue-700",children:"Haz clic en el mapa para comenzar a dibujar. Cuando termines, se te pedirá un nombre para la zona."}),e.jsx(u,{variant:"outline",size:"sm",className:"mt-2 w-full",onClick:vs,children:"Cancelar dibujo"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Zonas existentes"}),p.length===0?e.jsx("p",{className:"text-sm text-gray-500",children:"No hay zonas definidas"}):e.jsx("div",{className:"space-y-2",children:p.map(s=>e.jsxs("div",{className:`p-2 rounded-md border cursor-pointer ${(w==null?void 0:w.id)===s.id?"border-primary bg-primary/5":"border-gray-200"}`,onClick:()=>k(s),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-4 h-4 rounded-full",style:{backgroundColor:s.color}}),e.jsx("span",{className:"font-medium",children:s.name})]}),e.jsx(u,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:a=>{a.stopPropagation(),bs(s.id)},children:e.jsx(ce,{className:"h-3 w-3"})})]}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[s.type==="polygon"?"PolÃgono":"CÃrculo"," â¢",Cs(s.id).length," personas"]})]},s.id))})]})]})]})}),z&&e.jsx("div",{className:"absolute top-[72px] right-0 bottom-0 w-[350px] bg-white shadow-lg z-20 overflow-y-auto transition-transform",children:e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h2",{className:"text-lg font-medium",children:"Planificación de Ruta"}),e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>te(!1),children:e.jsx(V,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between mb-4",children:[e.jsxs(u,{variant:"outline",onClick:()=>ve(!E),className:`flex items-center gap-2 ${E?"bg-primary text-white":""}`,children:[e.jsx(Be,{className:"h-4 w-4"}),E?"Ocultar Ruta":"Mostrar Ruta"]}),e.jsxs(u,{variant:"outline",onClick:ps,disabled:Ce||d.length<2,className:"flex items-center gap-2",children:[e.jsx(Es,{className:"h-4 w-4"}),Ce?"Calculando...":"Calcular Distancias"]})]}),e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsxs(u,{variant:I==="DRIVING"?"default":"outline",size:"sm",onClick:()=>Le("DRIVING"),className:"flex-1",children:[e.jsx(zs,{className:"h-4 w-4 mr-2"}),"Auto"]}),e.jsxs(u,{variant:I==="WALKING"?"default":"outline",size:"sm",onClick:()=>Le("WALKING"),className:"flex-1",children:[e.jsx(Ps,{className:"h-4 w-4 mr-2"}),"Caminando"]}),e.jsxs(u,{variant:"destructive",size:"sm",onClick:js,className:"flex-1",children:[e.jsx(ce,{className:"h-4 w-4 mr-2"}),"Limpiar"]})]}),e.jsx("div",{className:"text-xs text-gray-500 mb-4",children:e.jsxs("p",{children:["El modo de transporte afecta al cálculo de distancias. ",!ne&&d.length>
5=2&&"Nota: La ruta se muestra como lÃnea recta porque el servicio de direcciones no está habilitado en la API."]})}),e.jsx("div",{className:"space-y-2",children:d.length===0?e.jsx("p",{className:"text-sm text-gray-500",children:'No hay puntos en la ruta. Haz clic en una ubicación en el mapa y selecciona "Añadir a ruta".'}):d.map(s=>e.jsxs("div",{className:"flex items-center justify-between p-2 border rounded",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"bg-primary text-white w-5 h-5 rounded-full flex items-center justify-center text-xs",children:s.order}),e.jsx("span",{className:"text-sm truncate",children:s.location.address})]}),e.jsx("div",{className:"flex gap-1",children:e.jsx(u,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>fs(s.location),children:e.jsx(ce,{className:"h-3 w-3"})})})]},`route-marker-${s.id}`))}),L.length>0&&e.jsxs("div",{className:"mt-6",children:[e.jsx("h3",{className:"text-sm font-medium mb-2",children:"Distancias calculadas"}),e.jsxs("div",{className:"space-y-2 border rounded p-3 bg-slate-50",children:[L.map((s,a)=>e.jsxs("div",{className:"text-sm",children:[e.jsxs("div",{className:"flex items-center gap-1 mb-1",children:[e.jsx("div",{className:"bg-primary text-white w-5 h-5 rounded-full flex items-center justify-center text-xs",children:a+1}),e.jsx("span",{className:"font-medium",children:"â"}),e.jsx("div",{className:"bg-primary text-white w-5 h-5 rounded-full flex items-center justify-center text-xs",children:a+2})]}),e.jsxs("div",{className:"ml-6 space-y-1",children:[e.jsxs("p",{children:["De: ",e.jsx("span",{className:"text-gray-700",children:s.origin.address})]}),e.jsxs("p",{children:["A: ",e.jsx("span",{className:"text-gray-700",children:s.destination.address})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-gray-500",children:"Distancia:"})," ",e.jsxs("span",{className:"font-medium",children:[(s.distance/1e3).toFixed(1)," km"]})]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-gray-500",children:"Tiempo:"})," ",e.jsxs("span",{className:"font-medium",children:[Math.round(s.duration/60)," min"]})]})]})]}),a<L.length-1&&e.jsx("div",{className:"border-b my-2"})]},a)),e.jsxs("div",{className:"border-t mt-3 pt-3",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"font-medium",children:"Distancia total:"}),e.jsxs("p",{className:"font-medium",children:[(L.reduce((s,a)=>s+a.distance,0)/1e3).toFixed(1)," km"]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"font-medium",children:"Tiempo total:"}),e.jsxs("p",{className:"font-medium",children:[Math.round(L.reduce((s,a)=>s+a.duration,0)/60)," min"]})]})]})]})]})]})]})}),rs&&w&&e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:e.jsxs(Is,{className:"w-full max-w-md",children:[e.jsxs(Fs,{children:[e.jsx($s,{children:"Guardar Zona"}),e.jsx(Rs,{children:"Asigna un nombre a la zona dibujada"})]}),e.jsx(Zs,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ve,{htmlFor:"zoneName",children:"Nombre de la Zona"}),e.jsx(Ue,{id:"zoneName",value:B,onChange:s=>Se(s.target.value),placeholder:"Ej: Zona Norte"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ve,{htmlFor:"zoneColor",children:"Color"}),e.jsx("div",{className:"flex gap-2",children:["#3B82F6","#EF4444","#10B981","#F59E0B","#8B5CF6","#EC4899"].map(s=>e.jsx("div",{className:`w-8 h-8 rounded-full cursor-pointer border-2 ${S===s?"border-black":"border-transparent"}`,style:{backgroundColor:s},onClick:()=>os(s)},s))})]})]})}),e.jsxs(Ts,{className:"flex justify-end gap-2",children:[e.jsx(u,{variant:"outline",onClick:()=>{A(!1),k(null)},children:"Cancelar"}),e.jsx(u,{onClick:us,disabled:B.trim()==="",children:"Guardar Zona"})]})]})})]})}export{ia as default};
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.