!function(e,n,o,t){e(function(){var i=e(".wc-shipping-zone-methods"),s=e(".wc-shipping-zone-method-rows"),d=e(".wc-shipping-zone-method-save"),a=o.template("wc-shipping-zone-method-row"),c=o.template("wc-shipping-zone-method-row-blank"),h=Backbone.Model.extend({changes:{},logChanges:function(e){var n=this.changes||{};_.each(e.methods,function(e,o){n.methods=n.methods||{methods:{}},n.methods[o]=_.extend(n.methods[o]||{instance_id:o},e)}),"undefined"!=typeof e.zone_name&&(n.zone_name=e.zone_name),"undefined"!=typeof e.zone_locations&&(n.zone_locations=e.zone_locations),"undefined"!=typeof e.zone_postcodes&&(n.zone_postcodes=e.zone_postcodes),this.changes=n,this.trigger("change:methods")},save:function(){var o=_.clone(this.changes);_.has(o,"zone_locations")&&_.isEmpty(o.zone_locations)&&(o.zone_locations=[""]),e.post(t+(t.indexOf("?")>0?"&":"?")+"action=woocommerce_shipping_zone_methods_save_changes",{wc_shipping_zones_nonce:n.wc_shipping_zones_nonce,changes:o,zone_id:n.zone_id},this.onSaveResponse,"json")},onSaveResponse:function(e,o){"success"===o&&(e.success?(e.data.zone_id!==n.zone_id&&(n.zone_id=e.data.zone_id,window.history.pushState&&window.history.pushState({},"","admin.php?page=wc-settings&tab=shipping&zone_id="+e.data.zone_id)),r.set("methods",e.data.methods),r.trigger("change:methods"),r.changes={},r.trigger("saved:methods"),window.onbeforeunload=null):window.alert(n.strings.save_failed))}}),p=Backbone.View.extend({rowTemplate:a,initialize:function(){this.listenTo(this.model,"change:methods",this.setUnloadConfirmation),this.listenTo(this.model,"saved:methods",this.clearUnloadConfirmation),this.listenTo(this.model,"saved:methods",this.render),this.listenTo(this.model,"rerender",this.render),s.on("change",{view:this},this.updateModelOnChange),s.on("sortupdate",{view:this},this.updateModelOnSort),e(window).on("beforeunload",{view:this},this.unloadConfirmation),d.on("click",{view:this},this.onSubmit),e(document.body).on("input change","#zone_name, #zone_locations, #zone_postcodes",{view:this},this.onUpdateZone),e(document.body).on("click",".wc-shipping-zone-method-settings",{view:this},this.onConfigureShippingMethod),e(document.body).on("click",".wc-shipping-zone-add-method",{view:this},this.onAddShippingMethod),e(document.body).on("wc_backbone_modal_response",this.onConfigureShippingMethodSubmitted),e(document.body).on("wc_region_picker_update",this.onUpdateZoneRegionPicker),e(document.body).on("wc_backbone_modal_next_response",this.onAddShippingMethodSubmitted),e(document.body).on("wc_backbone_modal_before_remove",this.onCloseConfigureShippingMethod),e(document.body).on("wc_backbone_modal_back_response",this.onConfigureShippingMethodBack),e(document.body).on("change",".wc-shipping-zone-method-selector select",this.onChangeShippingMethodSelector),e(document.body).on("click",".wc-shipping-zone-postcodes-toggle",this.onTogglePostcodes),e(document.body).on("wc_backbone_modal_validation",{view:this},this.validateFormArguments),e(document.body).on("wc_backbone_modal_loaded",{view:this},this.onModalLoaded)},onUpdateZoneRegionPicker:function(e){var n=e.detail,o={};o.zone_locations=n,l.model.set("zone_locations",n),l.model.logChanges(o)},onUpdateZone:function(n){var o=n.data.view,t=o.model,i=e(this).val(),s=e(n.target).data("attribute"),d={};n.preventDefault(),d[s]=i,t.set(s,i),t.logChanges(d),o.render()},block:function(){e(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){e(this.el).unblock()},render:function(){var o=_.indexBy(this.model.get("methods"),"instance_id"),t=this.model.get("zone_name"),i=this;e(".wc-shipping-zone-name").text(t||n.strings.default_zone_name),this.$el.empty(),this.unblock(),_.size(o)?(o=_.sortBy(o,function(e){return parseInt(e.method_order,10)}),e.each(o,function(e,o){"yes"===o.enabled?o.enabled_icon=''+n.strings.yes+"":o.enabled_icon=''+n.strings.no+"",i.$el.append(i.rowTemplate(o));var t=i.$el.find('tr[data-id="'+o.instance_id+'"]');if(!o.has_settings){t.find(".wc-shipping-zone-method-title > a").replaceWith(""+t.find(".wc-shipping-zone-method-title > a").text()+"");var s=t.find(".wc-shipping-zone-method-delete");t.find(".wc-shipping-zone-method-title .row-actions").empty().html(s)}}),this.$el.find(".wc-shipping-zone-method-delete").on("click",{view:this},this.onDeleteRow),this.$el.find(".wc-shipping-zone-method-enabled a").on("click",{view:this},this.onToggleEnabled)):i.$el.append(c),this.initTooltips()},initTooltips:function(){e("#tiptip_holder").removeAttr("style"),e("#tiptip_arrow").removeAttr("style"),e(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:50})},onSubmit:function(e){d.addClass("is-busy"),e.data.view.block(),e.data.view.model.save(),e.preventDefault()},onDeleteRow:function(o){var i=o.data.view,s=i.model,d=_.indexBy(s.get("methods"),"instance_id"),a={},c=e(this).closest("tr").data("id");o.preventDefault(),window.confirm(n.strings.delete_shipping_method_confirmation)&&(l.block(),e.post({url:t+(t.indexOf("?")>0?"&":"?")+"action=woocommerce_shipping_zone_remove_method",data:{wc_shipping_zones_nonce:n.wc_shipping_zones_nonce,instance_id:c,zone_id:n.zone_id},success:function({data:e}){delete d[c],a.methods=a.methods||e.methods,s.set("methods",d),s.logChanges(a),i.clearUnloadConfirmation(),i.render(),l.unblock()},error:function(e,o,t){window.alert(n.strings.remove_method_failed),l.unblock()},dataType:"json"}))},onToggleEnabled:function(n){var o=n.data.view,t=e(n.target),i=o.model,s=_.indexBy(i.get("methods"),"instance_id"),d=t.closest("tr").data("id"),a="yes"===t.closest("tr").data("enabled")?"no":"yes",c={};n.preventDefault(),s[d].enabled=a,c.methods=c.methods||{methods:{}},c.methods[d]=_.extend(c.methods[d]||{},{enabled:a}),i.set("methods",s),i.logChanges(c),o.render()},setUnloadConfirmation:function(){this.needsUnloadConfirm=!0,d.prop("disabled",!1),d.removeClass("is-busy")},clearUnloadConfirmation:function(){this.needsUnloadConfirm=!1,d.attr("disabled","disabled")},unloadConfirmation:function(e){if(e.data.view.needsUnloadConfirm)return e.returnValue=n.strings.unload_confirmation_msg,window.event.returnValue=n.strings.unload_confirmation_msg,n.strings.unload_confirmation_msg},updateModelOnChange:function(n){var o=n.data.view.model,t=e(n.target),i=t.closest("tr").data("id"),s=t.data("attribute"),d=t.val(),a=_.indexBy(o.get("methods"),"instance_id"),c={};a[i][s]!==d&&(c.methods[i]={},c.methods[i][s]=d,a[i][s]=d),o.logChanges(c)},updateModelOnSort:function(e){var n=e.data.view.model,o=_.indexBy(n.get("methods"),"instance_id"),t={};_.each(o,function(e){var n=parseInt(e.method_order,10),s=parseInt(i.find('tr[data-id="'+e.instance_id+'"]').index()+1,10);n!==s&&(o[e.instance_id].method_order=s,t.methods=t.methods||{methods:{}},t.methods[e.instance_id]=_.extend(t.methods[e.instance_id]||{},{method_order:s}))}),_.size(t)&&n.logChanges(t)},onConfigureShippingMethod:function(n){var o=e(this).closest("tr").data("id"),t=n.data.view.model,i=_.indexBy(t.get("methods"),"instance_id")[o];if(!i.settings_html)return!0;n.preventDefault(),i.settings_html=l.reformatSettingsHTML(i.settings_html),e(this).WCBackboneModal({template:"wc-modal-shipping-method-settings",variable:{instance_id:o,method:i,status:"existing"},data:{instance_id:o,method:i,status:"existing"}}),l.highlightOnFocus(".wc-shipping-modal-price"),e(document.body).trigger("init_tooltips")},onConfigureShippingMethodSubmitted:function(o,i,s){"wc-modal-shipping-method-settings"===i&&(l.block(),e.post(t+(t.indexOf("?")>0?"&":"?")+"action=woocommerce_shipping_zone_methods_save_settings",{wc_shipping_zones_nonce:n.wc_shipping_zones_nonce,instance_id:s.instance_id,data:s},function(o,t){"success"===t&&o.success?(e("table.wc-shipping-zone-methods").parent().find("#woocommerce_errors").remove(),o.data.errors.length>0&&l.showErrors(o.data.errors),_.size(l.model.changes)?l.model.save():l.model.onSaveResponse(o,t)):(window.alert(n.strings.save_failed),l.unblock())},"json"))},onConfigureShippingMethodBack:function(e,n){"wc-modal-shipping-method-settings"===n&&l.onAddShippingMethod(e)},showErrors:function(n){var o='
"+n+"
"}),o+="