import{r as ne}from"./index-DnB1XXdB.js";import{l as oe}from"./index-XP0w1PvT.js";var q={},g={};Object.defineProperty(g,"__esModule",{value:!0});g.loadGoogleMapScript=g.isBrowser=void 0;var D=typeof window<"u"&&window.document;g.isBrowser=D;var ae=function(t,r){if(!D||typeof google<"u"&&google.maps&&google.maps.api)return Promise.resolve();var n=document.querySelectorAll('script[src*="'.concat(t,'"]'));if(n&&n.length)return new Promise(function(s){if(typeof google<"u")return s();n[0].addEventListener("load",function(){return s()})});var i=new URL(r);i.searchParams.set("callback","__REACT_GOOGLE_AUTOCOMPLETE_CALLBACK__");var c=document.createElement("script");return c.src=i.toString(),new Promise(function(s){window.__REACT_GOOGLE_AUTOCOMPLETE_CALLBACK__=s,document.body.appendChild(c)})};g.loadGoogleMapScript=ae;var S={};Object.defineProperty(S,"__esModule",{value:!0});S.GOOGLE_MAP_SCRIPT_BASE_URL=void 0;var ie="https://maps.googleapis.com/maps/api/js";S.GOOGLE_MAP_SCRIPT_BASE_URL=ie;Object.defineProperty(q,"__esModule",{value:!0});var Se=q.default=_e,a=ne,U=se(oe),Q=g,ue=S;function se(e){return e&&e.__esModule?e:{default:e}}function K(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,n)}return r}function d(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?K(Object(r),!0).forEach(function(n){ce(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):K(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function ce(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _(e,t){return de(e)||fe(e,t)||pe(e,t)||le()}function le(){throw new TypeError(`Invalid attempt to destructure non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function pe(e,t){if(e){if(typeof e=="string")return $(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return $(e,t)}}function $(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function fe(e,t){var r=e&&(typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"]);if(r!=null){var n=[],i=!0,c=!1,s,l;try{for(r=r.call(e);!(i=(s=r.next()).done)&&(n.push(s.value),!(t&&n.length===t));i=!0);}catch(v){c=!0,l=v}finally{try{!i&&r.return!=null&&r.return()}finally{if(c)throw l}}return n}}function de(e){if(Array.isArray(e))return e}function _e(e){var t=e.apiKey,r=e.libraries,n=r===void 0?"places":r,i=e.googleMapsScriptBaseUrl,c=i===void 0?ue.GOOGLE_MAP_SCRIPT_BASE_URL:i,s=e.debounce,l=s===void 0?300:s,v=e.options,b=v===void 0?{}:v,P=e.sessionToken,O=e.language,V=O?"&language=".concat(O):"",A="".concat(c,"?key=").concat(t,"&libraries=").concat(n).concat(V),x=(0,a.useState)([]),w=_(x,2),H=w[0],L=w[1],W=(0,a.useState)(!1),h=_(W,2),z=h[0],y=h[1],F=(0,a.useState)(null),E=_(F,2),J=E[0],T=E[1],N=(0,a.useState)(!1),M=_(N,2),X=M[0],m=M[1],Y=(0,a.useState)(!1),G=_(Y,2),Z=G[0],C=G[1],ee=(0,a.useState)([]),R=_(ee,2),re=R[0],k=R[1],f=(0,a.useRef)(null),I=(0,a.useRef)(null),p=(0,a.useRef)(null),te=(0,a.useCallback)(function(){return(0,Q.loadGoogleMapScript)(c,A)},[c,A]),j=(0,a.useCallback)((0,U.default)(function(u){f.current&&u.input&&f.current.getPlacePredictions(d(d(d({},P&&p.current?{sessionToken:p.current}:{}),b),u),function(o){y(!1),L(o||[])})},l),[l]),B=(0,a.useCallback)((0,U.default)(function(u){f.current&&u.input&&f.current.getQueryPredictions(d(d(d({},P&&p.current?{sessionToken:p.current}:{}),b),u),function(o){m(!1),k(o||[])})},l),[l]);return(0,a.useEffect)(function(){if(Q.isBrowser){var u=function(){if(!google)return console.error("Google has not been found. Make sure your provide apiKey prop.");f.current=new google.maps.places.AutocompleteService,I.current=new google.maps.places.PlacesService(document.createElement("div")),P&&(p.current=new google.maps.places.AutocompleteSessionToken)};t?te().then(function(){return u()}):u()}},[]),{placesService:I.current,autocompleteSessionToken:p.current,placesAutocompleteService:f.current,placePredictions:J?H:[],isPlacePredictionsLoading:z,getPlacePredictions:function(o){if(o.input){T(o.input),y(!0),j(o);return}L([]),T(null),j(o),y(!1)},queryPredictions:Z?re:[],isQueryPredictionsLoading:X,getQueryPredictions:function(o){if(o.input){C(o.input),m(!0),B(o);return}k([]),C(null),B(o),m(!1)},refreshSessionToken:function(){p.current=new google.maps.places.AutocompleteSessionToken}}}export{Se as _};