import{s as f,x as _,N as u,A as g,o as s,c as n,a as m,w as x,u as i,F as C,P as L,t as $,e as P}from"./app-I4K73wff.js";import{l as k}from"./lodash-7_IUzYWg.js";import{s as w,a as A}from"./index-zzPOQKrQ.js";import{s as N}from"./index-Ikz2WuEn.js";const S={class:"relative w-full"},B={key:0,class:"absolute top-full left-0 w-full bg-white border rounded shadow max-h-52 overflow-y-auto z-50"},E=["onClick"],O="-76.24,4.28,-75.33,5.45",M={__name:"SearchMap",props:{defaultLocation:Object,disabled:Boolean},emits:["locationSelected"],setup(p,{emit:b}){const t=p,o=f(""),r=f([]),d=b,v=async()=>{if(o.value.length<3){r.value=[];return}try{const{data:e}=await u.get(`https://nominatim.openstreetmap.org/search?format=json&q=${o.value}&countrycodes=CO&addressdetails=1&viewbox=${O}&bounded=1`);r.value=e.filter(a=>a.address&&a.address.state==="Risaralda")}catch(e){console.error("Error al buscar ubicaciones:",e)}},y=k.debounce(v,500),c=e=>e.includes("Plazoleta de banderas, Universidad, AMCO")?"Universidad Tecnológica de Pereira, Conexión vial Álamos – Pinares, Los Alamos, Universidad, Perímetro Urbano Pereira, Pereira, Risaralda, RAP Eje Cafetero, 660003, Colombia":e,h=e=>{if(!e.display_name)return;const a=c(e.display_name);o.value=e.display_name,r.value=[],d("locationSelected",{lat:e.lat,lon:e.lon,name:a})};return _(async()=>{if(t.defaultLocation&&t.defaultLocation.lat&&t.defaultLocation.lon)try{const{data:e}=await u.get(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${t.defaultLocation.lat}&lon=${t.defaultLocation.lon}&countrycodes=CO`);if(e.display_name){const a=c(e.display_name);o.value=a,d("locationSelected",{lat:t.defaultLocation.lat,lon:t.defaultLocation.lon,name:a})}}catch(e){console.error("Error obteniendo el nombre de la ubicación:",e)}}),g(()=>t.defaultLocation,async e=>{if(e&&e.lat&&e.lon)try{const{data:a}=await u.get(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${e.lat}&lon=${e.lon}&countrycodes=CO`);if(a.display_name){const l=c(a.display_name);o.value=l,d("locationSelected",{lat:e.lat,lon:e.lon,name:l})}}catch(a){console.error("Error obteniendo el nombre de la ubicación:",a)}else o.value=""}),(e,a)=>(s(),n("div",S,[m(i(A),null,{default:x(()=>[m(i(w),{class:"pi pi-map-marker",style:{color:"#9333ea"}}),m(i(N),{modelValue:o.value,"onUpdate:modelValue":a[0]||(a[0]=l=>o.value=l),disabled:p.disabled,onInput:i(y),placeholder:"Buscar ubicación...",class:"border p-2 rounded w-full mt-1"},null,8,["modelValue","disabled","onInput"])]),_:1}),r.value.length?(s(),n("ul",B,[(s(!0),n(C,null,L(r.value,l=>(s(),n("li",{key:l.place_id,onClick:j=>h(l),class:"p-2 cursor-pointer hover:bg-gray-200"},$(l.display_name),9,E))),128))])):P("",!0)]))}};export{M as _};
