import{d as T,g as z,E as A,r,h as H,j as U,_ as j,o as c,k as u,l as v,a as I,n as t,B as N,C as O,t as f,p as w,q as R,F as B,v as q,G as K}from"./app-DZcRemIr.js";import{A as J}from"./AppLayout-O17sF3e2.js";import{l as i,i as Q,a as W}from"./marker-shadow-DiHTY0cK.js";import{S as X}from"./simpleDatePicker-CE9I3GgK.js";import"./AppSidebarLayout-DzMma2g7.js";import"./index-CA0zsXLm.js";import"./SiifIconBC3-DYQKLzWx.js";import"./useKbd-kRIii9yh.js";import"./SelectValue-CSZtknPb.js";import"./useNonce-PBIDXYJz.js";const Y=T({__name:"Gps",setup(F,{expose:a}){a();const _=[{label:"SIIF",href:"/dashboard"},{label:"Consulta Gerencial"}];i.Icon.Default.mergeOptions({iconUrl:W,shadowUrl:Q});const e=r(null);let n;const d=r(null),o=r("SUBEROK"),b=r(),h=r(),p=r([]),m=r([]),x=r(0),y=r(!1),g=r(null);z(()=>{e.value&&(n=i.map(e.value).setView([10.5,-66.9],13),i.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{attribution:"© OpenStreetMap contributors"}).addTo(n),d.value=i.layerGroup().addTo(n))}),A(()=>{n&&n.remove()});const D=async()=>{if(!o.value||!b.value||!h.value){g.value="Todos los campos son obligatorios.";return}y.value=!0,g.value=null,C();try{const s=await H.get("/api/gerencial/gps/ruta",{params:{idRFV:o.value,fechaDesde:b.value,fechaHasta:h.value}});p.value=s.data.ruta,m.value=s.data.leyenda,x.value=s.data.totalVisitas,V()}catch(s){console.error("Error al obtener la ruta:",s),g.value="No se pudo obtener la ruta. Por favor, intente de nuevo."}finally{y.value=!1}},V=()=>{if(!d.value||p.value.length===0)return;const s=[],M=new Map(m.value.map(l=>[l.actividad,l.color]));p.value.forEach(l=>{const S=parseFloat(l.latitud),L=parseFloat(l.longitud);s.push([S,L]);const E=M.get(l.nombre_actividad)||"#CCCCCC",G=i.divIcon({html:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="${E}" width="28" height="28"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z"/></svg>`,className:"",iconSize:[28,28],iconAnchor:[14,28],popupAnchor:[0,-28]}),P=`
      <div class="font-sans">
        <strong class="text-base">${l.nombre_cliente}</strong><br>
        <strong>Actividad:</strong> ${l.nombre_actividad}<br>
        <strong>Especialidad:</strong> ${l.nombre_especialidad}<br>
        <strong>Fecha:</strong> ${new Date(l.fecha_actividad).toLocaleString()}<br>
        <strong>Obs:</strong> ${l.observaciones_cliente}
      </div>
    `;i.marker([S,L],{icon:G}).addTo(d.value).bindPopup(P)}),s.length>1&&i.polyline(s,{color:"#003366",weight:3,opacity:.7}).addTo(d.value),d.value&&n.fitBounds(d.value.getBounds(),{padding:[50,50]})},C=()=>{var s;(s=d.value)==null||s.clearLayers(),p.value=[],m.value=[],x.value=0},k={breadcrumbs:_,mapContainer:e,get map(){return n},set map(s){n=s},routeLayerGroup:d,idRFV:o,fechaDesde:b,fechaHasta:h,ruta:p,leyenda:m,totalVisitas:x,isLoading:y,error:g,buscarRuta:D,dibujarRutaEnMapa:V,limpiarMapa:C,AppLayout:J,get Head(){return U},SimpleDatePicker:X};return Object.defineProperty(k,"__isScriptSetup",{enumerable:!1,value:!0}),k}}),Z={class:"flex flex-col lg:flex-row gap-4 p-4"},$={class:"w-full lg:w-3/4 h-[550px] rounded-xl overflow-hidden shadow-md border border-gray-450"},ee={ref:"mapContainer",class:"w-full h-full"},ae={class:"w-full lg:w-1/4 flex flex-col items-start space-y-4"},te={class:"w-full p-4 border rounded-xl shadow-sm bg-white space-y-3"},oe={key:0,class:"text-sm text-red-600 bg-red-100 p-2 rounded"},se=["disabled"],le={key:0,class:"animate-spin h-5 w-5 text-white",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24"},re={key:0,class:"w-full p-4 border rounded-xl shadow-sm bg-white space-y-3"},ne={class:"text-sm font-medium text-gray-600"},de={class:"font-bold text-gray-800"},ie={class:"space-y-2"},ce={class:"flex items-center gap-2"},ue={class:"font-bold bg-gray-200 px-2 py-0.5 rounded-full"};function pe(F,a,_,e,n,d){return c(),u(B,null,[v(e.Head,{title:"GPS"}),v(e.AppLayout,{breadcrumbs:e.breadcrumbs},{default:I(()=>[t("div",Z,[t("div",$,[t("div",ee,null,512)]),t("div",ae,[t("div",te,[a[5]||(a[5]=t("h3",{class:"font-bold text-lg text-gray-800"},"Parámetros de Búsqueda",-1)),t("div",null,[a[3]||(a[3]=t("label",{for:"idRFV",class:"block text-sm font-medium text-gray-700"},"ID Representante (RFV)",-1)),N(t("input",{type:"text",id:"idRFV","onUpdate:modelValue":a[0]||(a[0]=o=>e.idRFV=o),class:"w-full mt-1 border border-gray-300 rounded px-3 py-2 focus:outline-none focus:ring focus:ring-blue-300 text-sm"},null,512),[[O,e.idRFV]])]),v(e.SimpleDatePicker,{modelValue:e.fechaDesde,"onUpdate:modelValue":a[1]||(a[1]=o=>e.fechaDesde=o)},null,8,["modelValue"]),v(e.SimpleDatePicker,{modelValue:e.fechaHasta,"onUpdate:modelValue":a[2]||(a[2]=o=>e.fechaHasta=o)},null,8,["modelValue"]),e.error?(c(),u("div",oe,f(e.error),1)):w("v-if",!0),t("button",{onClick:e.buscarRuta,disabled:e.isLoading,class:"w-full bg-gray-600 text-white font-medium py-2 px-4 rounded-xl hover:bg-gray-700 transition disabled:bg-gray-400 disabled:cursor-not-allowed flex items-center justify-center gap-2"},[e.isLoading?(c(),u("svg",le,[...a[4]||(a[4]=[t("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"},null,-1),t("path",{class:"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"},null,-1)])])):w("v-if",!0),R(" "+f(e.isLoading?"Buscando...":"Buscar Ruta"),1)],8,se)]),e.ruta.length>0&&!e.isLoading?(c(),u("div",re,[a[7]||(a[7]=t("h3",{class:"font-bold text-lg text-gray-800"},"Resultados",-1)),t("p",ne,[a[6]||(a[6]=R("Total de Visitas: ",-1)),t("span",de,f(e.totalVisitas),1)]),a[8]||(a[8]=t("hr",null,null,-1)),a[9]||(a[9]=t("h4",{class:"font-semibold text-md text-gray-700"},"Leyenda",-1)),t("ul",ie,[(c(!0),u(B,null,q(e.leyenda,o=>(c(),u("li",{key:o.actividad,class:"flex items-center justify-between text-sm"},[t("div",ce,[t("span",{class:"block w-4 h-4 rounded-full",style:K({backgroundColor:o.color})},null,4),t("span",null,f(o.actividad),1)]),t("span",ue,f(o.cantidad),1)]))),128))])])):w("v-if",!0)])])]),_:1})],64)}const Ve=j(Y,[["render",pe],["__file","/var/www/resources/js/pages/Gps.vue"]]);export{Ve as default};
