Liferay.Loader.define("dynamic-data-mapping-form-field-type@6.0.145/SearchLocation/usePlaces.es",["module","exports","require","liferay!frontend-js-react-web$react"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=a("liferay!frontend-js-react-web$react");const loadScript=(e,t,a,n)=>{let o=document.getElementById("googleMapsScript");if(!o){o=document.createElement("script"),o.addEventListener("load",(()=>{o.setAttribute("data-loaded","true")})),o.setAttribute("id","googleMapsScript"),o.setAttribute("type","text/javascript");let e="https://maps.googleapis.com/maps/api/js?libraries=places";a&&(e+="&key="+a),o.setAttribute("src",e)}o.dataset.loaded?n():o.addEventListener("load",n);const r=document.getElementById(t);r&&!e&&r.appendChild(o)};function handleScriptLoad(e,t,a,n){const o=document.getElementById(t);e.current=new window.google.maps.places.Autocomplete(o),e.current.setFields(["address_component","formatted_address"]);a(e.current.addListener("place_changed",(()=>async function handlePlaceSelect(e,t){const a=e.current.getPlace(),n=null==a?void 0:a.address_components,o={administrative_area_level_1:"short_name",administrative_area_level_2:"long_name",country:"long_name",locality:"long_name",postal_code:"short_name",route:"long_name",street_number:"long_name"},r={administrative_area_level_1:"",administrative_area_level_2:"",country:"",formatted_address:null==a?void 0:a.formatted_address,locality:"",postal_code:"",route:"",street_number:""};for(let e=0;e<n.length;e++){const t=n[e].types[0];r[t]=n[e][o[t]]}t({target:{value:JSON.stringify({address:r.street_number+" "+r.route,city:r.locality,country:r.country,place:r.formatted_address,"postal-code":r.postal_code,state:r.administrative_area_level_1})}})}(e,n))))}var _default=({elementId:e,googlePlacesAPIKey:t,isReadOnly:a,onChange:o,viewMode:r})=>{const d=(0,n.useRef)(),[s,l]=(0,n.useState)(),[c,i]=(0,n.useState)();(0,n.useEffect)((()=>{if(r)return loadScript(a,e,t,(()=>handleScriptLoad(d,e,l,i))),()=>{window.google.maps.event.removeListener(s)}}),[]),(0,n.useEffect)((()=>{r&&c&&o(c)}),[c]),(0,n.useEffect)((()=>{const onScroll=()=>{const t=document.querySelector('.pac-container:not([style*="display: none"])'),a=document.getElementById(e);if(t&&a===document.activeElement){const{height:e,top:n}=null==a?void 0:a.getBoundingClientRect(),o=window.pageYOffset||document.documentElement.scrollTop;t.style.top=e+o+n+"px"}};return document.addEventListener("scroll",onScroll,!0),()=>document.removeEventListener("scroll",onScroll,!0)}),[])};t.default=_default}}));
//# sourceMappingURL=usePlaces.es.js.map