(()=>{"use strict";var t={n:e=>{var o=e&&e.__esModule?()=>e.default:()=>e;return t.d(o,{a:o}),o},d:(e,o)=>{for(var n in o)t.o(o,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:o[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};const e=window.wp.i18n,o=window.wp.apiFetch;var n=t.n(o);const r=function(t,o){const r={form:t(".dokan-product-rejection-form"),rejectButton:t(".dokan-product-rejection-form .dokan-reject-product-action"),reasonField:t(".dokan-product-rejection-form #rejection_reason"),productId:t("#post_ID").val(),postType:t("#post_type").val(),originalStatus:t("#original_post_status").val(),statusDisplay:t("#post-status-display")},a={showLoading(t,e){const o=t.text();return e=null!=e?e:t.prop("disabled",!0).text(e),t.prop("disabled",!0).text(e),o},hideLoading(t,e){t.prop("disabled",!1).text(e)},showError(t){o("",{icon:"error",title:(0,e.__)("Error","dokan"),text:t})},showSuccess:async t=>o("",{icon:"success",title:t,showConfirmButton:!1,timer:1500}),validateReason(t){return(t=t.trim())?!(t.length>500&&(this.showError((0,e.__)("Rejection reason cannot exceed 500 characters","dokan")),1)):(this.showError((0,e.__)("Please write the reason for rejecting the product","dokan")),!1)}},c={async confirmRejection(){const t=await o("",{title:(0,e.__)("Reject Product?","dokan"),text:(0,e.__)("This will reject the product and notify the vendor. Are you sure?","dokan"),icon:"warning",action:"confirm",showCancelButton:!0,confirmButtonText:(0,e.__)("Confirm","dokan"),cancelButtonText:(0,e.__)("Cancel","dokan")});return t?.isConfirmed},promptForReason:async()=>o("",{title:(0,e.__)("Reject Product?","dokan"),text:(0,e.__)("Please provide a reason for rejecting this product:","dokan"),action:"prompt",input:"textarea",showCancelButton:!0,confirmButtonText:(0,e.__)("Reject","dokan"),cancelButtonText:(0,e.__)("Cancel","dokan")})},i={async submitRejection(t,o){try{const e=await n()({path:"/dokan/v1/product-rejection/reject",method:"POST",data:{product_id:t,reason:o}});return e&&e.status&&"reject"===e.status}catch(t){return a.showError(t.message||(0,e.__)("Error rejecting product","dokan")),!1}}},s={async handleMetaboxRejection(t){t.preventDefault();const o=r.reasonField.val();if(!a.validateReason.call(a,o))return;if(!await c.confirmRejection())return;const n=a.showLoading(r.rejectButton,(0,e.__)("Processing rejection…","dokan"));await i.submitRejection(r.productId,o)&&(await a.showSuccess((0,e.__)("Product rejected successfully","dokan")),window.location.reload()),a.hideLoading(r.rejectButton,n)},async handleRowRejection(o){o.preventDefault(),o.stopPropagation();const n=t(o.currentTarget).data("product-id"),r=await c.promptForReason();if(!r||!r.isConfirmed)return;const s=r.value;a.validateReason.call(a,s)&&await i.submitRejection(n,s)&&(await a.showSuccess((0,e.__)("Product rejected successfully","dokan")),window.location.reload())}};return{init(){r.form.length&&r.rejectButton.on("click",s.handleMetaboxRejection),t(document).on("click",".reject-product",s.handleRowRejection),"product"===r.postType&&"reject"===r.originalStatus&&r.statusDisplay.text((0,e.__)("Rejected","dokan"))}}}(window.jQuery,window.dokan_sweetalert);jQuery(document).ready(()=>{r.init()})})();