(()=>{"use strict";var a={n:e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return a.d(t,{a:t}),t},d:(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o:(a,e)=>Object.prototype.hasOwnProperty.call(a,e)};const e=window.jQuery;var t=a.n(e);const r=window.wp.apiFetch;var o=a.n(r);t()(a=>{function e(e){"show"===e&&a("#wca-loader").addClass("flex"),"hide"===e&&a("#wca-loader").removeClass("flex")}function t(e,t){a("#wca-alert-popup").addClass(t),a("#wca-alert-popup .wca-alert-content").text(e),a("#wca-alert-overlay").show()}a("#login")?.show(),a(document).on("submit","#wca-application-form",function(r){if(r.preventDefault(),a(".wca-error").text(""),"on"===WC_AFFILIATE_FRONT.enable_recaptcha&&0===grecaptcha.getResponse().length)return r.preventDefault(),!1;const c={};a(this).serializeArray().forEach(a=>{c[a.name]=a.value}),e("show"),o()({path:"/wc-affiliate/v1/affiliates/apply",method:"POST",data:c}).then(r=>{r.success?(t(r.message),setTimeout(()=>{e("hide"),location.reload()},3e3)):(e("hide"),r.data&&"object"==typeof r.data?(r.data.password&&a("#wca-pass-error").text(r.data.password),r.data.email&&a("#wca-email-error").text(r.data.email),r.data.user_name&&a("#wca-uname-error").text(r.data.user_name)):t(r.message||r.data,"danger"))}).catch(a=>{e("hide"),t("An error occurred while submitting your application.","danger"),alert(a.message)})}),a(document).on("click","#wca-upload-btn",e=>{e.preventDefault();const t=wp.media({title:"Upload Image",multiple:!1}).open().on("select",()=>{const e=t.state().get("selection").first().toJSON().url;a("#image_url").val(e),a("#wca-avatar img").attr("src",e),a(".wca-dashboard-profile-image img").attr("src",e)})}),a(document).on("click",".wca-tab-btn",function(){const e=a(this).attr("data-tab");a(".wca-tab-btn").removeClass("active"),a(this).addClass("active"),a(".wca-tab-content").removeClass("active"),a(`#wca-${e}-form`).addClass("active")})})})();