Liferay.Loader.define("journal-web@5.0.105/js/LocaleChangedHandler.es",["module","exports","require","frontend-js-web"],(function(e,a,t){window;{Object.defineProperty(a,"__esModule",{value:!0}),a.default=a.LocaleChangedHandler=void 0;var n=t("frontend-js-web");class LocaleChangedHandler{constructor({contentTitle:e,context:a,defaultLanguageId:t,namespace:n,onDefaultLocaleChangedCallback:l,onLocaleChangedCallback:d}){this.contentTitle=e,this.defaultLanguageId=t,this.namespace=n,this.onDefaultLocaleChangedCallback=l,this.onLocaleChangedCallback=d,this.context=a,this.attach()}attach(){this._defaultLocaleChangedHandler=Liferay.after("inputLocalized:defaultLocaleChanged",this._onDefaultLocaleChange.bind(this)),this._localeChangedHandler=Liferay.after("inputLocalized:localeChanged",this._onLocaleChange.bind(this))}detach(){this._defaultLocaleChangedHandler.detach(),this._localeChangedHandler.detach()}_onDefaultLocaleChange(e){e.item&&(this.defaultLanguageId=e.item.getAttribute("data-value"),this.onDefaultLocaleChangedCallback&&this.onDefaultLocaleChangedCallback(this.defaultLanguageId))}_onLocaleChange(e){const a=e.item.getAttribute("data-value");this._selectedLanguageId=a,a&&(this._updateLocalizableInput("descriptionMapAsXML",this.defaultLanguageId,a),this._updateLocalizableInput(this.contentTitle,this.defaultLanguageId,a),this._updateLanguageIdInput(a)),this.onLocaleChangedCallback&&this.onLocaleChangedCallback(this.context,a)}_updateLanguageIdInput(e){document.getElementById(this.namespace+"languageId").value=e}_updateLocalizableInput(e,a,t){const l=Liferay.component(this.namespace+e);if(l){if(""===l.getValue(t)){const e=l.getValue(a),d=n.AOP.before((()=>n.AOP.prevent()),l,"updateInputLanguage");l.selectFlag(t),l.updateInput(e),setTimeout((()=>{d.detach()}),400)}}}}a.LocaleChangedHandler=LocaleChangedHandler;var l=LocaleChangedHandler;a.default=l}}));
//# sourceMappingURL=LocaleChangedHandler.es.js.map