import{r as e}from"./chunk-QTnfLwEv.js";import{n as t,t as n}from"./jsx-runtime-BWRPWl8p.js";import{Da as r,Ei as i,Er as a,Ia as o,La as s,Ma as c,W as l,ma as u}from"./index-DccLTdzK.js";import{t as d}from"./MapQuest-ab6x0npL.js";import{n as f}from"./coordenadas-CMuA2BP0.js";var p=e(t(),1),m=n(),h=({setCenter:e,setMaker:t})=>{let n=()=>{r.success(`¡Coordenadas registradas éxitosamente!`,{position:r.POSITION.TOP_RIGHT,autoClose:2e3})},[l,d]=(0,p.useState)(``),h=()=>{try{c(s(o())).then(e=>{let{data:t}=e;d(t.nombre)}).catch(e=>{e.message===`Network Error`&&r.error(`Conexión al servidor no disponible`)})}catch(e){console.log(e)}};return(0,p.useEffect)(()=>{h()},[]),(0,m.jsx)(`div`,{style:{textAlign:`center`,marginTop:`2%`,marginBottom:`2%`},children:(0,m.jsxs)(u,{onClick:async()=>{if(!navigator.geolocation){r.error(`El navegador no soporta geolocalización`,{position:r.POSITION.TOP_RIGHT,autoClose:2e3});return}navigator.geolocation.getCurrentPosition(async r=>{let{latitude:i,longitude:a}=r.coords,o=await(await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${i}&lon=${a}&zoom=18&addressdetails=1`,{headers:{"User-Agent":`LaboratorioApp/1.0`}})).json();e&&e(i,a),t&&t(i,a,`Mi ubicacion`);let s=o.address||{};f({latitud:i,longitud:a,ubicacion:`${s.road||s.pedestrian||s.suburb||``}, ${s.city||s.town||s.village||s.municipality||s.county||``}, ${s.state||``}, ${s.country||``}`,usuario:l,estado:`true`}),n()},e=>{alert(`Error al obtener ubicación`)})},variant:`danger`,children:[(0,m.jsx)(i,{icon:a}),`\xA0 Ubicar`]})})},g=()=>{let[e,t]=(0,p.useState)(`20.394990760246436`),[n,r]=(0,p.useState)(`-99.98675954006715`),[i,a]=(0,p.useState)(!0);(0,p.useEffect)(()=>{setTimeout(()=>{a(!1)},500)},[]);let o=[];return(0,m.jsxs)(m.Fragment,{children:[i&&(0,m.jsx)(l,{}),(0,m.jsxs)(`div`,{className:`containerFluid`,children:[(0,m.jsx)(`div`,{children:(0,m.jsx)(`div`,{children:(0,m.jsx)(h,{setCenter:(e,n)=>{t(e),r(n),window.L.mapquest.Map.getMap(`map`).setView(new window.L.LatLng(e,n),12)},setMaker:(e,t,n)=>{let r=window.L.mapquest.textMarker(new window.L.LatLng(e,t),{text:n||``,subtext:``,position:`right`,type:`marker`,icon:{primaryColor:`#a8190f`,secondaryColor:`db2c2c`,size:`md`}}).addTo(window.L.mapquest.Map.getMap(`map`));o.push(r)}})})}),(0,m.jsx)(`div`,{children:(0,m.jsx)(d,{height:`80vh`,width:`100%`,center:[e,n],tileLayer:`map`,zoom:12,apiKey:``})})]})]})};export{g as MapaUbicacion};