!function(c,r,p,l){c(function(){var s=c(".wc-shipping-zone-methods"),e=c(".wc-shipping-zone-method-rows"),n=c(".wc-shipping-zone-method-save"),t=p.template("wc-shipping-zone-method-row"),o=p.template("wc-shipping-zone-method-row-blank"),i=Backbone.Model.extend({changes:{},logChanges:function(e){var t=this.changes||{};_.each(e.methods,function(e,n){t.methods=t.methods||{methods:{}},t.methods[n]=_.extend(t.methods[n]||{instance_id:n},e)}),"undefined"!=typeof e.zone_name&&(t.zone_name=e.zone_name),"undefined"!=typeof e.zone_locations&&(t.zone_locations=e.zone_locations),"undefined"!=typeof e.zone_postcodes&&(t.zone_postcodes=e.zone_postcodes),this.changes=t,this.trigger("change:methods")},save:function(){c.post(l+(0'+r.strings.yes+"":n.enabled_icon=''+r.strings.no+"",i.$el.append(i.rowTemplate(n));var t=i.$el.find('tr[data-id="'+n.instance_id+'"]');if(!n.has_settings){t.find(".wc-shipping-zone-method-title > a").replaceWith(""+t.find(".wc-shipping-zone-method-title > a").text()+"");var o=t.find(".wc-shipping-zone-method-delete");t.find(".wc-shipping-zone-method-title .row-actions").empty().html(o)}}),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(o),this.initTooltips()},initTooltips:function(){c("#tiptip_holder").removeAttr("style"),c("#tiptip_arrow").removeAttr("style"),c(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:50})},onSubmit:function(e){e.data.view.block(),e.data.view.model.save(),e.preventDefault()},onDeleteRow:function(e){var n=e.data.view,t=n.model,o=_.indexBy(t.get("methods"),"instance_id"),i={},s=c(this).closest("tr").data("id");e.preventDefault(),delete o[s],i.methods=i.methods||{methods:{}},i.methods[s]=_.extend(i.methods[s]||{},{deleted:"deleted"}),t.set("methods",o),t.logChanges(i),n.render()},onToggleEnabled:function(e){var n=e.data.view,t=c(e.target),o=n.model,i=_.indexBy(o.get("methods"),"instance_id"),s=t.closest("tr").data("id"),d="yes"===t.closest("tr").data("enabled")?"no":"yes",a={};e.preventDefault(),i[s].enabled=d,a.methods=a.methods||{methods:{}},a.methods[s]=_.extend(a.methods[s]||{},{enabled:d}),o.set("methods",i),o.logChanges(a),n.render()},setUnloadConfirmation:function(){this.needsUnloadConfirm=!0,n.removeAttr("disabled")},clearUnloadConfirmation:function(){this.needsUnloadConfirm=!1,n.attr("disabled","disabled")},unloadConfirmation:function(e){if(e.data.view.needsUnloadConfirm)return e.returnValue=r.strings.unload_confirmation_msg,window.event.returnValue=r.strings.unload_confirmation_msg,r.strings.unload_confirmation_msg},updateModelOnChange:function(e){var n=e.data.view.model,t=c(e.target),o=t.closest("tr").data("id"),i=t.data("attribute"),s=t.val(),d=_.indexBy(n.get("methods"),"instance_id"),a={};d[o][i]!==s&&(a.methods[o]={},a.methods[o][i]=s,d[o][i]=s),n.logChanges(a)},updateModelOnSort:function(e){var n=e.data.view.model,o=_.indexBy(n.get("methods"),"instance_id"),i={};_.each(o,function(e){var n=parseInt(e.method_order,10),t=parseInt(s.find('tr[data-id="'+e.instance_id+'"]').index()+1,10);n!==t&&(o[e.instance_id].method_order=t,i.methods=i.methods||{methods:{}},i.methods[e.instance_id]=_.extend(i.methods[e.instance_id]||{},{method_order:t}))}),_.size(i)&&n.logChanges(i)},onConfigureShippingMethod:function(e){var n=c(this).closest("tr").data("id"),t=e.data.view.model,o=_.indexBy(t.get("methods"),"instance_id")[n];if(!o.settings_html)return!0;e.preventDefault(),c(this).WCBackboneModal({template:"wc-modal-shipping-method-settings",variable:{instance_id:n,method:o},data:{instance_id:n,method:o}}),c(document.body).trigger("init_tooltips")},onConfigureShippingMethodSubmitted:function(e,n,t){"wc-modal-shipping-method-settings"===n&&(h.block(),c.post(l+(0"+n+"
"}),t+="",c("table.wc-shipping-zone-methods").before(t)},onAddShippingMethod:function(e){e.preventDefault(),c(this).WCBackboneModal({template:"wc-modal-add-shipping-method",variable:{zone_id:r.zone_id}}),c(".wc-shipping-zone-method-selector select").change()},onAddShippingMethodSubmitted:function(e,n,t){"wc-modal-add-shipping-method"===n&&(h.block(),c.post(l+(0'+e+""),c(this).closest("article").height(c(this).parent().height())},onTogglePostcodes:function(e){e.preventDefault();var n=c(this).closest("tr");n.find(".wc-shipping-zone-postcodes").show(),n.find(".wc-shipping-zone-postcodes-toggle").hide()}}),a=new i({methods:r.methods,zone_name:r.zone_name}),h=new d({model:a,el:e});h.render(),e.sortable({items:"tr",cursor:"move",axis:"y",handle:"td.wc-shipping-zone-method-sort",scrollSensitivity:40})})}(jQuery,shippingZoneMethodsLocalizeScript,wp,ajaxurl);