(()=>{var s={80928:s=>{void 0===TCB_Front.js_modules["user-profile"]&&TCB_Front.setModuleLoadedStatus("user-profile",!1),function(r,t){if(TCB_Front.isModuleLoaded("user-profile"))return;const e=["nickname","username","first_name","last_name"];class i{usedDisplayNames=[];$errorContainer=r();inputErrorClass="tve-up-error";isValid=!0;constructor(s){s.hasClass("tve-user-profile")||(s=s.find(".tve-user-profile")),s.length&&!s.data("tcb.userprofile")&&(this.$el=s,this.$form=this.$el.find("form"),this.readFormData(),this.bindEvents(),this.autofillData(),s.data("tcb.userprofile",this),t.$window.on("tve_after_content_toggle",((s,r)=>{1===this.$form.closest(r).length&&(this.readFormData(),this.autofillData())})))}readFormData(){this.getInputs().each(((s,t)=>{const e=t.getAttribute("name");e&&(this[`$${e}`]=r(t),"display_name"===e&&(this.$dropdown=this.$form.find(".tve-lg-dropdown-list"),this.$option=this.$dropdown.children().first(),this.$dropdown.empty()))}));let s={success_message:"Success",error_message:{email:"Email address invalid",required:"Required field missing",passwordmismatch:"Password mismatch"}};try{s=JSON.parse(this.$el.find(".tve-up-messages").val())}catch(s){}Object.assign(this,s)}bindEvents(){this.$form.on("submit",(s=>(this.submitForm(s),s.preventDefault(),s.stopPropagation(),!1))),this.$form.find(".tve-form-button .tve-form-button-submit").on("click",(s=>(s.preventDefault(),s.stopPropagation(),this.$form.submit(),!1))),this.$display_name&&e.forEach((s=>{this[`$${s}`]&&this[`$${s}`].on("blur",(()=>{this.buildDisplayNameOptions()}))}))}validateForm(){this.fieldErrors=[],this.isValid=!0,this.getInputs().each(((s,r)=>{let t=!0;const e=r.getAttribute("name"),i=r.value.trim();"1"!==r.dataset.required||i.length||(t=!1,this.fieldErrors.includes(this.error_message.required)||this.fieldErrors.push(this.error_message.required)),"user_email"===e&&(t=TCB_Front.Utils.isEmail(i),t||this.fieldErrors.push(this.error_message.email)),t||(r.classList.add(this.inputErrorClass),this.isValid=!1)})),this.$pass1&&(this.$pass1.siblings(".tve-password-strength-wrapper").attr("data-score")<=30&&(this.fieldErrors.push(this.error_message.password_score||"Please choose a stronger password. Try including numbers, symbols, and a mix of upper and lowercase letters and remove common words."),this.isValid=!1),this.$pass2&&this.$pass1.val()!==this.$pass2.val()&&(this.$pass1.addClass(this.inputErrorClass),this.$pass2.addClass(this.inputErrorClass),this.fieldErrors.push(this.error_message.passwordmismatch),this.isValid=!1))}submitForm(){if(this.clearErrors(),this.validateForm(),this.isValid){let s=`${this.$form.serialize()}&form-nonce=${tve_frontend_options.user_profile_nonce}&action=tve_user_profile_update&url=${encodeURIComponent(location.href)}`;s+=`&form_id=${this.$el.attr("id")}`,this.$form.tve_form_loading(),tve_frontend_options.post_id&&(s+=`&post_id=${tve_frontend_options.post_id}`),ThriveGlobal.$j.ajax({type:"post",xhrFields:{withCredentials:!0},url:tve_frontend_options.ajaxurl,dataType:"json",data:s}).fail((()=>{TCB_Front.Utils.toast("An error occurred while submitting your data. Please try again",!0)})).done((s=>{if(s.success)TCB_Front.Utils.toast(this.success_message);else if(this.fieldErrors=[],"string"==typeof s.errors)TCB_Front.Utils.toast(s.errors,!0);else{const r=s.errors.errors;Object.keys(r).forEach((s=>{this.error_message[s]?this.fieldErrors.push(this.error_message[s]):r[s].forEach((s=>this.fieldErrors.push(s)))})),this.fieldErrors.length&&this.displayFormError()}})).always((()=>{this.$form.tve_form_loading(!0)}))}else this.displayFormError()}autofillData(){r.isEmptyObject(tve_frontend_options.current_user)||Object.keys(tve_frontend_options.current_user).forEach((s=>{this[`$${s}`]&&this[`$${s}`].val(tve_frontend_options.current_user[s])})),this.$display_name&&(this.buildDisplayNameOptions(),this.$dropdown.find(`li[data-value="${tve_frontend_options.current_user.display_name.replace(/"/g,'\\"')}"]`).trigger("mousedown"))}buildDisplayNameOptions(){const s={oldSavedValue:tve_frontend_options.current_user.display_name};e.forEach((r=>{this[`$${r}`]&&(s[`${r}`]=this[`$${r}`].val())})),s.first_name&&s.last_name&&(s.first_last=`${s.first_name} ${s.last_name}`,s.last_first=`${s.last_name} ${s.first_name}`),Object.keys(s).forEach((r=>{if(s[r].trim()&&!this.usedDisplayNames.includes(s[r])){const e=this.$option.clone();e.attr("data-value",s[r]).css("display","").find("span").text(s[r]),this.$dropdown.append(e),this.usedDisplayNames.push(s[r]),t.inlineCssVariable(this.$dropdown,{"--rows":this.$dropdown.children().length})}}))}displayFormError(){this.$errorContainer.length||(this.$errorContainer=r('<div id="tve-up-error-container"></div>').prependTo(this.$form.parent()),this.$errorContainer.append(`<a href="javascript:void(0)" class="tve-up-err-close" title="Close"><span class="thrv-icon thrv-svg-icon">${TCB_Front.icons.get("cross")}</span></a>`),this.$errorContainer.on("click",".tve-up-err-close",this.closeErrors.bind(this))),this.fieldErrors.forEach((s=>{r(`<div class="tve-up-error-message">${s}</div>`).prependTo(this.$errorContainer)})),setTimeout((()=>{const s=parseInt(this.$form.css("margin-top"));let r=-10-this.$errorContainer.outerHeight(!0)-(isNaN(s)?0:s);this.$el.offset().top+r<0&&(r=0),this.$errorContainer.css({top:`${r}px`,width:this.$form.outerWidth()}).fadeIn(200)}),50)}closeErrors(){let s=this.$form.find(`.${this.inputErrorClass}`).first();s.length||(s=this.getInputs().first()),s.trigger("focus"),this.clearErrors(!1)}clearErrors(s=!0){this.$errorContainer.find(".tve-up-error-message").remove(),this.$errorContainer.fadeOut(200),s&&this.$form.find(`.${this.inputErrorClass}`).removeClass(this.inputErrorClass)}getInputs(){return this.$form.find("input,textarea,select").filter(':not([type="hidden"]):visible')}}t.$window.on("tcb_after_dom_ready",(()=>{TCB_Front.Utils.isEditorPage()||r(".tve-user-profile").each(((s,t)=>new i(r(t))))})),window.TCB_Front.UserProfile=i,s.exports=i,TCB_Front.setModuleLoadedStatus("user-profile",!0)}(ThriveGlobal.$j,TCB_Front)}},r={};!function t(e){var i=r[e];if(void 0!==i)return i.exports;var o=r[e]={exports:{}};return s[e](o,o.exports,t),o.exports}(80928)})();