Liferay.Loader.define("dynamic-data-mapping-form-field-type@6.0.108/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 e=(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 o(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(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",postal_code:"short_name",route:"long_name"},r={administrative_area_level_1:"",administrative_area_level_2:"",country:"",formatted_address:null==a?void 0:a.formatted_address,postal_code:"",route:""};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.route,city:r.administrative_area_level_2,country:r.country,place:r.formatted_address,"postal-code":r.postal_code,state:r.administrative_area_level_1})}})}(e,n))))}var r=({elementId:t,googlePlacesAPIKey:a,isReadOnly:r,onChange:s,viewMode:d})=>{const l=(0,n.useRef)(),[c,i]=(0,n.useState)(),[u,m]=(0,n.useState)();(0,n.useEffect)((()=>{if(d)return e(r,t,a,(()=>o(l,t,i,m))),()=>{window.google.maps.event.removeListener(c)}}),[]),(0,n.useEffect)((()=>{d&&u&&s(u)}),[u]),(0,n.useEffect)((()=>{const e=()=>{const e=document.querySelector('.pac-container:not([style*="display: none"])'),a=document.getElementById(t);if(e&&a===document.activeElement){const{height:t,top:n}=null==a?void 0:a.getBoundingClientRect(),o=window.pageYOffset||document.documentElement.scrollTop;e.style.top=t+o+n+"px"}};return document.addEventListener("scroll",e,!0),()=>document.removeEventListener("scroll",e,!0)}),[])};t.default=r}}));
//# sourceMappingURL=usePlaces.es.js.map