(()=>{var e,r;window.eu_owb=window.eu_owb||{},window.eu_owb.order_withdrawal=window.eu_owb.order_withdrawal||{},e=jQuery,(r=window.eu_owb).order_withdrawal={params:{},startTime:0,init:function(){var a=r.order_withdrawal;a.params=eu_owb_woocommerce_order_withdrawal_params,a.startTime=a.getTimestampSec(),e(document).on("submit",".order-withdrawal-request",a.onSubmitOrderRequest),e(document).on("change",".order-withdrawal-request #order-withdrawal-request-order",a.onChangeOrder),e(document).on("change",".order-withdrawal-request #manually-select-items",a.onSelectItems),e(document).on("change",".order-withdrawal-request #select-all-items",a.selectAllItems),e(document).on("change",".order-withdrawal-request #order-withdrawal-request-order-number, .order-withdrawal-request #order-withdrawal-request-email",a.onChangeInputs)},onChangeInputs:function(){var a=r.order_withdrawal,t=e(this).parents("form"),d=t.find("#order-withdrawal-request-order-number").val(),o=t.find("#order-withdrawal-request-email").val(),i=t.find(".order-supports-partial-withdrawal"),n=t.serialize();i.length<=0||(d&&a.isEmail(o)?e.ajax({type:"POST",url:a.params.wc_ajax_url.toString().replace("%%endpoint%%","eu_owb_woocommerce_order_withdrawal_request_supports_partial"),data:n,dataType:"json"}).done(function(e){!0===e.data.supports_partial_withdrawal?i.removeClass("hidden"):i.addClass("hidden")}).fail(function(e){i.addClass("hidden")}):i.addClass("hidden"))},selectAllItems:function(){r.order_withdrawal;var a=e(this).parents("form").find(".order-withdrawal-request-items-table");e(this).is(":checked")?a.find(".order-withdrawal-request-item-checkbox").prop("checked",!0):a.find(".order-withdrawal-request-item-checkbox").prop("checked",!1)},onSelectItems:function(){r.order_withdrawal,e(this).parents("form").find(".order-withdrawal-request-items-table").toggleClass("hidden")},isEmail:function(e){return/^\S+@\S+\.\S+$/.test(e)},onChangeOrder:function(){var a=r.order_withdrawal,t=e(this).parents("form"),d=t.find(".eu-owb-notice-wrapper"),o=t.find(".button[type=submit]"),i=t.serialize(),n=e(this).val(),s=t.find("#original-order-id").length>0?t.find("#original-order-id").val():0,l=t.find(".order-withdrawal-delete-original-request-checkbox");return d.find(".notice").remove(),t.addClass("loading"),t.find(":input:not(.disabled):not([type=hidden])").prop("disabled",!0),o.prop("disabled",!0).addClass("loading"),t.find(".eu-owb-order-item-select-wrapper").addClass("loading"),l.length>0&&(n===s?l.addClass("hidden"):l.removeClass("hidden")),e.ajax({type:"POST",url:a.params.wc_ajax_url.toString().replace("%%endpoint%%","eu_owb_woocommerce_order_withdrawal_request_select_order"),data:i,dataType:"json"}).done(function(e){t.removeClass("loading"),t.find(":input:not(.disabled):not([type=hidden])").prop("disabled",!1),t.find(".eu-owb-order-item-select-wrapper").removeClass("loading"),o.prop("disabled",!1).removeClass("loading"),t.find(".eu-owb-order-item-select-wrapper").html(e.html).show()}).fail(function(r){t.removeClass("loading"),t.find(":input:not(.disabled):not([type=hidden])").prop("disabled",!1),o.prop("disabled",!1).removeClass("loading"),t.find(".eu-owb-order-item-select-wrapper").removeClass("loading"),t.find(".eu-owb-order-item-select-wrapper").html("").hide();try{var a=JSON.parse(r.responseText)}catch(e){a={}}n&&(e.each(a.data,function(e,r){d.append('<p class="woocommerce-error notice">'+r.message+"</p>")}),d[0].scrollIntoView({behavior:"smooth",block:"start"}))}),!1},getTimestampSec:function(){return Math.floor(Date.now()/1e3)},onSubmitOrderRequest:function(){var a=r.order_withdrawal,t=e(this),d=t.find(".eu-owb-notice-wrapper"),o=t.find(".button[type=submit]"),i=t.serialize(),n=a.getTimestampSec();return d.find(".notice").remove(),t.addClass("loading"),t.find(":input:not(.disabled):not([type=hidden])").prop("disabled",!0),o.prop("disabled",!0).addClass("loading"),e.ajax({type:"POST",url:a.params.wc_ajax_url.toString().replace("%%endpoint%%","eu_owb_woocommerce_order_withdrawal_request"),data:i+"&start_timestamp="+a.startTime+"&end_timestamp="+n,dataType:"json"}).done(function(e){t.removeClass("loading"),t.find(":input:not(.disabled):not([type=hidden])").prop("disabled",!1),t.find(".eu-owb-form-fields").hide(),o.hide(),d.append('<p class="woocommerce-message">'+e.data+"</p>"),d[0].scrollIntoView({behavior:"smooth",block:"start"}),a.startTime=a.getTimestampSec()}).fail(function(r){t.removeClass("loading"),t.find(":input:not(.disabled):not([type=hidden])").prop("disabled",!1),o.prop("disabled",!1).removeClass("loading");try{var i=JSON.parse(r.responseText)}catch(e){i={}}e.each(i.data,function(e,r){d.append('<p class="woocommerce-error notice">'+r.message+"</p>")}),d[0].scrollIntoView({behavior:"smooth",block:"start"}),a.startTime=a.getTimestampSec()}),!1}},e(document).ready(function(){r.order_withdrawal.init()}),((window.owbWC=window.owbWC||{}).static=window.owbWC.static||{})["order-withdrawal"]={}})();