// @bun
var{defineProperty:Q,getOwnPropertyNames:_,getOwnPropertyDescriptor:$}=Object,b=Object.prototype.hasOwnProperty;function x(k){return this[k]}var P=(k)=>{var q=(U??=new WeakMap).get(k),B;if(q)return q;if(q=Q({},"__esModule",{value:!0}),k&&typeof k==="object"||typeof k==="function"){for(var F of _(k))if(!b.call(q,F))Q(q,F,{get:x.bind(k,F),enumerable:!(B=$(k,F))||B.enumerable})}return U.set(k,q),q},U;var E=(k)=>k;function G(k,q){this[k]=E.bind(null,q)}var j=(k,q)=>{for(var B in q)Q(k,B,{get:q[B],enumerable:!0,configurable:!0,set:G.bind(q,B)})};var g=(k,q)=>()=>(k&&(q=k(k=0)),q);var v=import.meta.require;function y(k){return new Promise((q,B)=>{if(!navigator.geolocation){B(Error("Geolocation is not supported"));return}navigator.geolocation.getCurrentPosition(q,B,k)})}function W(k,q,B,F){let K=k*Math.PI/180,C=B*Math.PI/180,D=(B-k)*Math.PI/180,J=(F-q)*Math.PI/180,L=Math.sin(D/2)*Math.sin(D/2)+Math.cos(K)*Math.cos(C)*Math.sin(J/2)*Math.sin(J/2);return 6371000*(2*Math.atan2(Math.sqrt(L),Math.sqrt(1-L)))}function H(k={}){let{enableHighAccuracy:q=!0,timeout:B=1e4,maximumAge:F=0,immediate:N=!0}=k,K=typeof navigator<"u"&&"geolocation"in navigator,C={coords:null,timestamp:null,error:null,loading:!1,supported:K},D=[],J=null,L=!0,M=()=>{D.forEach((z)=>z(C))},R=(z)=>{C={...C,coords:{latitude:z.coords.latitude,longitude:z.coords.longitude,altitude:z.coords.altitude,accuracy:z.coords.accuracy,altitudeAccuracy:z.coords.altitudeAccuracy,heading:z.coords.heading,speed:z.coords.speed},timestamp:z.timestamp,error:null,loading:!1},M()},S=(z)=>{C={...C,error:z,loading:!1},M()},O=()=>{if(!K||J!==null)return;C={...C,loading:!0},M(),J=navigator.geolocation.watchPosition(R,S,{enableHighAccuracy:q,timeout:B,maximumAge:F})},T=()=>{if(J!==null)navigator.geolocation.clearWatch(J),J=null},V=()=>{if(!K)return;C={...C,loading:!0},M(),navigator.geolocation.getCurrentPosition(R,S,{enableHighAccuracy:q,timeout:B,maximumAge:F})},X=()=>{L=!1,T()},Y=()=>{if(L=!0,D.length>0)O()};if(N&&K)O();return{get:()=>C,subscribe:(z)=>{if(D.push(z),z(C),D.length===1&&L&&K&&!N)O();return()=>{if(D=D.filter((Z)=>Z!==z),D.length===0)T()}},refresh:V,pause:X,resume:Y}}function w(k){return H({...k,immediate:!0})}export{w as useGeolocationWatch,H as useGeolocation,y as getCurrentPosition,W as calculateDistance};
