(()=>{var i,r;window.shiptastic=window.shiptastic||{},window.shiptastic.admin=window.shiptastic.admin||{},i=jQuery,(r=window.shiptastic).admin.shipping_providers={params:{},$wrapper:"",init:function(){var e=r.admin.shipping_providers;e.params=wc_shiptastic_admin_shipping_providers_params,e.$wrapper=i(".wc-stc-shipping-providers"),i(document).on("click",".wc-stc-shipping-provider-delete",e.onRemoveProvider).on("change",".wc-stc-shipping-providers input.wc-stc-shipping-provider-activated-checkbox",this.onChangeProviderStatus),i(window).on("load",(function(){i(document).on("updateMoveButtons","table.wc-stc-shipping-providers",e.onChangeSort)})),i("table.wc-stc-shipping-providers tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:"td.sort",scrollSensitivity:40,helper:function(r,e){return e.children().each((function(){i(this).width(i(this).width())})),e.css("left","0"),e},start:function(i,r){r.item.css("background-color","#f6f6f6")},stop:function(i,r){r.item.removeAttr("style"),r.item.trigger("updateMoveButtons")}})},onChangeSort:function(){var e=i(this).find('input[name="provider_order[]"]').map((function(){return i(this).val()})).get(),o=r.admin.shipping_providers,n={action:"woocommerce_stc_sort_shipping_provider",order:e,security:o.getParams().sort_shipping_provider_nonce};o.doAjax(n)},onChangeProviderStatus:function(){var e=r.admin.shipping_providers,o=i(this),n=e.getProviderName(o),t=o.parents("td").find(".woocommerce-stc-input-toggle"),s={action:"woocommerce_stc_edit_shipping_provider_status",enable:o.is(":checked")?"yes":"no",provider:n};window.onbeforeunload="",t.addClass("woocommerce-input-toggle--loading"),e.doAjax(s,e.onChangeProviderStatusSucess)},onChangeProviderStatusSucess:function(i){var e=r.admin.shipping_providers.$wrapper.find('tr[data-shipping-provider="'+i.provider+'"]').find(".woocommerce-stc-input-toggle");e.removeClass("woocommerce-input-toggle--loading"),e.removeClass("woocommerce-input-toggle--enabled, woocommerce-input-toggle--disabled"),"yes"===i.activated?e.addClass("woocommerce-input-toggle--enabled"):e.addClass("woocommerce-input-toggle--disabled")},getProviderName:function(i){return r.admin.shipping_providers,i.data("shipping-provider")?i.data("shipping-provider"):i.parents("tr").length>0&&i.parents("tr").data("shipping-provider")},onRemoveProvider:function(){var e=r.admin.shipping_providers,o=e.getProviderName(i(this));return o&&window.confirm(e.getParams().i18n_remove_shipping_provider_notice)&&e.removeProvider(o),!1},removeProvider:function(i){var e=r.admin.shipping_providers,o={action:"woocommerce_stc_remove_shipping_provider",provider:i,security:e.getParams().remove_shipping_provider_nonce};e.block(),e.doAjax(o,e.onRemoveProviderSuccess)},onRemoveProviderSuccess:function(i){var e=r.admin.shipping_providers.$wrapper.find('tr[data-shipping-provider="'+i.provider+'"]');e.length>0&&e.remove()},block:function(){r.admin.shipping_providers.$wrapper.block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){r.admin.shipping_providers.$wrapper.unblock()},doAjax:function(e,o,n){var t=r.admin.shipping_providers,s=t.params.ajax_url,p=t.$wrapper;o=o||t.onAjaxSuccess,n=n||t.onAjaxError,e.hasOwnProperty("security")||(e.security=t.params.edit_shipping_providers_nonce),i.ajax({type:"POST",url:s,data:e,success:function(i){i.success?(o.apply(p,[i]),t.unblock()):(n.apply(p,[i]),t.unblock())},error:function(i){n.apply(p,[i])},dataType:"json"})},onAjaxError:function(i){},onAjaxSuccess:function(i){},getParams:function(){return r.admin.shipping_providers.params}},i(document).ready((function(){r.admin.shipping_providers.init()})),((window.wcShiptastic=window.wcShiptastic||{}).static=window.wcShiptastic.static||{})["admin-shipping-providers"]={}})();