(()=>{"use strict";var o={n:e=>{var a=e&&e.__esModule?()=>e.default:()=>e;return o.d(a,{a}),a},d:(e,a)=>{for(var s in a)o.o(a,s)&&!o.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:a[s]})},o:(o,e)=>Object.prototype.hasOwnProperty.call(o,e)};const e=window.jQuery;var a=o.n(e);dokan.reportAbuse={button:null,form_html:"",form_title:"",flashMessage:"",init(){const o=this;a()(".dokan-report-abuse-button").on("click",(function(e){if(e.preventDefault(),o.button=this,"on"===dokanReportAbuse.reported_by_logged_in_users_only&&!dokanReportAbuse.is_user_logged_in)return a()("body").trigger("dokan:login_form_popup:show");o.getForm()})),a()("body").on("dokan:login_form_popup:fetching_form",(()=>{o.showLoadingAnim()})),a()("body").on("dokan:login_form_popup:fetched_form",(()=>{o.stopLoadingAnim()})),a()("body").on("dokan:login_form_popup:logged_in",((e,a)=>{dokanReportAbuse.is_user_logged_in=!0,dokanReportAbuse.nonce=a.data.dokan_report_abuse_nonce,o.getForm()})),a()("body").on("submit","#dokan-report-abuse-form-popup form",(function(e){e.preventDefault(),o.submitForm(this)}))},showLoadingAnim(){a()(this.button).addClass("working").children("i").removeClass("fa-flag").addClass("fa-spin fa-refresh")},stopLoadingAnim(){a()(this.button).removeClass("working").children("i").removeClass("fa-spin fa-refresh").addClass("fa-flag")},submittingForm(){a()("#dokan-report-abuse-form-popup fieldset").prop("disabled",!0),a()("#dokan-report-abuse-form-submit-btn").addClass("dokan-hide"),a()("#dokan-report-abuse-form-working-btn").removeClass("dokan-hide")},submittedForm(){a()("#dokan-report-abuse-form-popup fieldset").prop("disabled",!1),a()("#dokan-report-abuse-form-submit-btn").removeClass("dokan-hide"),a()("#dokan-report-abuse-form-working-btn").addClass("dokan-hide")},getForm(){const o=this;o.form_html?o.showPopup():(o.showLoadingAnim(),a().ajax({url:dokan.ajaxurl,method:"get",dataType:"json",data:{_wpnonce:dokanReportAbuse.nonce,action:"dokan_report_abuse_get_form"}}).done((e=>{o.form_html=e.data.html,o.form_title=e.data.title,o.showPopup()})).always((()=>{o.stopLoadingAnim()})))},showPopup(){const o=this;a()("body").append('<div id="dokan-modal-report-abuse-popup"></div>');const e=a()("#dokan-modal-report-abuse-popup").iziModal({headerColor:dokan.modal_header_color,width:690,onClosed:()=>{o.afterPopupClose()}});e.iziModal("setTitle",o.form_title),e.iziModal("setContent",o.form_html),e.iziModal("open")},afterPopupClose(){this.flashMessage&&(dokan_sweetalert(this.flashMessage,{icon:"success"}),this.flashMessage="")},submitForm(o){const e=this,s=(a()(o).serialize(),a()(".dokan-popup-error","#dokan-report-abuse-form-popup"));s.removeClass("has-error").text(""),e.submittingForm(),a().ajax({url:dokan.ajaxurl,method:"post",dataType:"json",data:{_wpnonce:dokanReportAbuse.nonce,action:"dokan_report_abuse_submit_form",form_data:{reason:a()(o).find('[name="reason"]:checked').val(),product_id:dokanReportAbuse.product_id,customer_name:a()(o).find('[name="customer_name"]').val(),customer_email:a()(o).find('[name="customer_email"]').val(),description:a()(o).find('[name="description"]').val()}}}).done((o=>{e.flashMessage=o.data.message,a()("#dokan-modal-report-abuse-popup").iziModal("close")})).always((()=>{e.submittedForm()})).fail((o=>{o.responseJSON&&o.responseJSON.data&&o.responseJSON.data.message&&s.addClass("has-error").text(o.responseJSON.data.message)}))}},dokan.reportAbuse.init()})();