Liferay.Loader.define("users-admin-web@6.0.70/js/UserNameFields.es",["module","exports","require","frontend-js-web"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s=a("frontend-js-web");class e extends s.PortletBase{attached(){this.languageIdSelectNode.addEventListener("change",this._handleSelectChange)}created(e){this.baseURL=e.baseURL,this.formNode=this._setElement(e.formNode),this.languageIdSelectNode=this._setElement(e.languageIdSelectNode),this.userNameFieldsNode=this._setElement(e.userNameFieldsNode),this._handleSelectChange=this._handleSelectChange.bind(this),this._formDataCache={},this._maxLengthsCache={},this._loadingAnimationMarkupText='<div class="loading-animation" id="'.concat(this.portletNamespace,'loadingUserNameFields"></div>')}detached(){super.detached(),this.languageIdSelectNode.removeEventListener("change",this._handleSelectChange)}updateUserNameFields(e){this._setUp(),this._getURL(e).then(fetch).then((e=>e.text())).then(this._insertUserNameFields.bind(this)).then(this._cleanUp.bind(this)).catch(this._handleError.bind(this))}_cacheData(){const e=new FormData(this.formNode);e.forEach&&e.forEach(((e,t)=>{const a=this.userNameFieldsNode.querySelector("#"+t);a&&(this._formDataCache[t]=e,a.hasAttribute("maxLength")&&(this._maxLengthsCache[t]=a.getAttribute("maxLength")))}))}_createLoadingIndicator(){this.userNameFieldsNode.insertAdjacentHTML("beforebegin",this._loadingAnimationMarkupText),this.userNameFieldsNode.classList.add("hide")}_cleanUp(){this._removeLoadingIndicator(),this._populateData()}_getURL(e){return new Promise((t=>{t((0,s.createPortletURL)(this.baseURL,{languageId:e}))}))}_handleError(e){console.error(e),this._removeLoadingIndicator()}_handleSelectChange(e){this.updateUserNameFields(e.currentTarget.value)}_insertUserNameFields(e){const t=document.implementation.createHTMLDocument("");t.body.innerHTML=e;const a=t.getElementById("".concat(this.portletNamespace,"userNameFields"));a&&(this.userNameFieldsNode.innerHTML=a.innerHTML)}_populateData(){Object.entries(this._formDataCache).forEach((([e,t])=>{const a=this.userNameFieldsNode.querySelector("#"+e);a&&(a.value=t,Object.hasOwnProperty.call(this._maxLengthsCache,e)&&a.setAttribute("maxLength",this._maxLengthsCache[e]))}))}_removeLoadingIndicator(){const e=this.one("#loadingUserNameFields");e&&e.remove(),this.userNameFieldsNode.classList.remove("hide")}_setElement(e){return"string"==typeof e?this.one(e):e}_setUp(){this._cacheData(),this._createLoadingIndicator()}}var i=e;t.default=i}}));
//# sourceMappingURL=UserNameFields.es.js.map