(()=>{var t,e;window.shiptastic=window.shiptastic||{},window.shiptastic.admin=window.shiptastic.admin||{},t=jQuery,(e=window.shiptastic).admin.shipment_settings={params:{},init:function(){var n=e.admin.shipment_settings;n.params=wc_shiptastic_admin_settings_params,t(document).on("change shiptastic_show_or_hide_fields","table.form-table :input[id]",n.onChangeInput).on("click",".wc_input_table a.add",n.onAddInputRow).on("change",".stc-search-shipping-provider",n.onChangeProviderSearch);try{t(document.body).on("wc-enhanced-select-init wc-stc-enhanced-select-init",n.onEnhancedSelectInit).trigger("wc-stc-enhanced-select-init")}catch(t){window.console.log(t)}t("table.form-table :input[id]").trigger("shiptastic_show_or_hide_fields")},onChangeProviderSearch:function(){let e=t(this).find(":selected").data("data");e.hasOwnProperty("text")&&e.text&&t("#shipping_provider_title").val(e.text),e.hasOwnProperty("tracking_url")&&e.tracking_url&&t("#shipping_provider_tracking_url_placeholder").val(e.tracking_url)},onEnhancedSelectInit:function(){var n=e.admin.shipment_settings;t(":input.stc-search-shipping-provider").filter(":not(.enhanced)").each((function(){!function(e,n){t(e).selectWoo(n).addClass("enhanced")}(this,{allowClear:!!t(this).data("allow_clear"),placeholder:t(this).data("placeholder"),minimumInputLength:t(this).data("minimum_input_length")?t(this).data("minimum_input_length"):"1",templateResult:function(e){return e.icon?t('<span class="stc-provider-result-wrapper"><img src="'+e.icon+'" class="provider-icon" /> '+e.text+"</span>"):e.text},ajax:{url:n.params.ajax_url,dataType:"json",delay:250,data:function(e){return{provider:e.term,action:t(this).data("action")||"woocommerce_stc_json_search_shipping_providers",security:n.params.search_shipping_providers_nonce,exclude:t(this).data("exclude"),limit:t(this).data("limit")}},processResults:function(e){let n=[];return e&&!e.error&&t.each(e,(function(t,e){n.push(e)})),{results:n}},cache:!0}})}))},onAddInputRow:function(){e.admin.shipment_settings;var n=t(this).parents(".wc_input_table"),i=n.find("tbody tr.item:visible").length,a=n.find("tr.template").clone();return a.find(":input").each((function(){t(this).attr("name",t(this).attr("name").replace("size",i))})),a.appendTo(n.find("tbody")).removeClass("template").show(),t(document.body).trigger("wc-enhanced-select-init"),!1},getCleanInputId:function(t){var n=e.admin.shipment_settings,i=t.attr("id")?t.attr("id"):t.attr("name");if(n.params.hasOwnProperty("clean_input_callback")){var a=n.params.clean_input_callback,s=[],r="",c="";"shiptastic.admin."===a.substring(0,17)?(s=(a=a.slice(17)).split("."),r=e.admin[s[0]],c=s[1]):(s=a.split("."),r=window[s[0]],c=s[1]),"object"==typeof r&&r.hasOwnProperty(c)&&(i=r[c](t))}return i||""},getInputByIdOrName:function(n,i){var a=e.admin.shipment_settings;return i=a.getCleanDataId(i),n.find(":input").filter((function(){var e=a.getCleanInputId(t(this));return!!e&&a.getCleanDataId(e)===i}))},getCleanDataId:function(t){return t.toLowerCase().replace(/-/g,"")},onChangeInput:function(){var n,i,a,s,r,c,d,o,p,h=e.admin.shipment_settings,l=t(this),u=t(this).parents("form"),m=h.getCleanInputId(l),_=u.find(":input[data-show_if_"+t.escapeSelector(m)+"]");t.each(_,(function(){for(var e in n=t(this),i=n.parents("tr"),a=n.data(),s=!0,a)if(a.hasOwnProperty(e)&&"show_if_"===e.substring(0,8)&&(r=e.replace("show_if_",""),c=h.getInputByIdOrName(u,r),d=n.data(e)?n.data(e).split(","):[],c.length>0&&(o=c.val(),p=!1,c.is(":radio")?"no"!==(o=c.parents("fieldset").find(":checked").length>0?c.parents("fieldset").find(":checked").val():"no")&&(p=!0):c.is(":checkbox")?"yes"==(o=c.is(":checked")?"yes":"no")&&(p=!0):p=void 0!==o&&"0"!==o&&""!==o,d&&d.length>0?-1===t.inArray(o,d)&&(s=!1):p||(s=!1)),!s))break;s?0===i.length?(n.parents("fieldset").show(),n.parents("fieldset").prev("label").show()):i.show():0===i.length?(n.parents("fieldset").hide(),n.parents("fieldset").prev("label").hide()):i.hide()}))}},t(document).ready((function(){e.admin.shipment_settings.init()})),((window.wcShiptastic=window.wcShiptastic||{}).static=window.wcShiptastic.static||{})["admin-settings"]={}})();