Liferay.Loader.define("account-admin-web@2.0.37/account_users_admin/js/AccountUserEmailDomainValidator.es",["module","exports","require","frontend-js-web","frontend-js-metal-web$metal-state"],(function(e,i,t){window;{Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var a=t("frontend-js-web"),s=t("frontend-js-metal-web$metal-state");class e extends a.PortletBase{attached(){const e=this.getForm_(this.ns("fm"));e?this.decorateEmailAddressField_(e):Liferay.once(this.ns("formReady"),(e=>{const i=this.getForm_(e.formName);i&&this.decorateEmailAddressField_(i)}),this)}addFieldMessage_(e){const i=document.createElement("div");i.className="form-text";const t=document.createElement("button");t.className="btn btn-link btn-unstyled link-secondary",t.innerText=Liferay.Language.get("view-valid-domains"),t.onclick=()=>{this.openDialog_(this.viewValidDomainsURL)},t.type="button",i.appendChild(t),e.placeAfter(i)}addFormFieldRules_(e,i){const t=e.get("fieldRules");e.set("fieldRules",t.concat(i))}decorateEmailAddressField_(e){const i=e.formValidator.getField(this.ns("emailAddress"));this.viewValidDomainsURL&&this.addFieldMessage_(i);const t=this.getEmailDomainFieldRule_();this.addFormFieldRules_(e,[t]),this.setWarningValidationStyle_(e,i,t.validatorName)}getEmailDomainFieldRule_(){const e=this.accountEntryNames,i=this.blockedDomains?this.blockedDomains.split(","):this.blockedDomains,t=this.validDomains?this.validDomains.split(","):this.validDomains,a="emailDomain";return{body(a,s){const n=a.substr(a.indexOf("@")+1);var o,r=!1;if(i&&i.includes(n)?(r=!0,o=Liferay.Util.sub(Liferay.Language.get("x-is-a-blocked-domain"),n)):t&&!t.includes(n)&&(r=!0,o=Liferay.Util.sub(Liferay.Language.get("x-is-not-a-valid-domain-for-the-following-accounts-x"),n,e)),r){const e=s.get("name"),i=this.get("fieldStrings");return i[e]||(i[e]={}),i[e].emailDomain=o,!1}return!0},custom:!0,fieldName:this.ns("emailAddress"),validatorName:a}}getForm_(e){var i;return null===(i=Liferay.Form)||void 0===i?void 0:i.get(e)}onSubmitError_(e,i,t,a){e.preventDefault();const s=e.validator.errors[t.get("name")];1===s.length&&s[0]===a&&(submitForm(i),e.halt())}openDialog_(e){Liferay.Util.openWindow({dialog:{destroyOnHide:!0,height:400,modal:!0,resizable:!1,width:600},title:Liferay.Language.get("valid-domains"),uri:e})}setWarningValidationStyle_(e,i,t){const a=e.formValidator;a.after("errorField",(e=>{if(e.validator.field===i&&e.validator.errors[0]===t){const e=a.findFieldContainer(i);e&&e.replaceClass("has-error","has-warning")}}));const s=a.resetFieldCss;a.resetFieldCss=function(e){if(s.apply(a,[e]),e===i){var t=a.findFieldContainer(e);t&&t.removeClass("has-warning")}},a.on("submitError",(a=>{this.onSubmitError_(a,e,i,t)}),this)}}e.STATE={accountEntryNames:s.Config.string,blockedDomains:s.Config.string,validDomains:s.Config.string,viewValidDomainsURL:s.Config.string};var n=e;i.default=n}}));
//# sourceMappingURL=AccountUserEmailDomainValidator.es.js.map