text: jQuery(function(p){window.wcTracks=window.wcTracks||{},window.wcTracks.recordEvent=window.wcTracks.recordEvent||function(){};var w={states:null,init:function(){"undefined"!=typeof woocommerce_admin_meta_boxes_order&&"undefined"!=typeof woocommerce_admin_meta_boxes_order.countries&&(this.states=p.parseJSON(woocommerce_admin_meta_boxes_order.countries.replace(/&quot;/g,'"'))),p(".js_field-country").selectWoo().change(this.change_country),p(".js_field-country").trigger("change",[!0]),p(document.body).on("change","select.js_field-state",this.change_state),p("#woocommerce-order-actions input, #woocommerce-order-actions a").click(function(){window.onbeforeunload=""}),p("a.edit_address").click(this.edit_address),p("a.billing-same-as-shipping").on("click",this.copy_billing_to_shipping),p("a.load_customer_billing").on("click",this.load_billing),p("a.load_customer_shipping").on("click",this.load_shipping),p("#customer_user").on("change",this.change_customer_user)},change_country:function(e,o){if(void 0===o&&(o=!1),null!==w.states){var t,a=p(this),r=a.val(),i=a.parents("div.edit_address").find(":input.js_field-state"),n=i.parent(),d=i.val(),c=i.attr("name"),_=i.attr("id"),s=a.data("woocommerce.stickState-"+r)?a.data("woocommerce.stickState-"+r):d,m=i.attr("placeholder");if(o&&a.data("woocommerce.stickState-"+r,s),n.show().find(".select2-container").remove(),p.isEmptyObject(w.states[r]))t=p('<input type="text" />').prop("id",_).prop("name",c).prop("placeholder",m).addClass("js_field-state").val(d),i.replaceWith(t);else{var l=w.states[r],u=p('<option value=""></option>').text(woocommerce_admin_meta_boxes_order.i18n_select_state_text);t=p("<select></select>").prop("id",_).prop("name",c).prop("placeholder",m).addClass("js_field-state select short").append(u),p.each(l,function(e){var o=p("<option></option>").prop("value",e).text(l[e]);e===d&&o.prop("selected"),t.append(o)}),t.val(s),i.replaceWith(t),t.show().selectWoo().hide().change()}p(document.body).trigger("contry-change.woocommerce",[r,p(this).closest("div")]),p(document.body).trigger("country-change.woocommerce",[r,p(this).closest("div")])}},change_state:function(){var e=p(this),o=e.val(),t=e.parents("div.edit_address").find(":input.js_field-country"),a=t.val();t.data("woocommerce.stickState-"+a,o)},init_tiptip:function(){p("#tiptip_holder").removeAttr("style"),p("#tiptip_arrow").removeAttr("style"),p(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200})},edit_address:function(e){e.preventDefault();var o=p(this),t=o.closest(".order_data_column"),a=t.find("div.edit_address"),r=t.find("div.address"),i=a.find(".js_field-country"),n=a.find(".js_field-state"),d=Boolean(a.find('input[name^="_billing_"]').length);r.hide(),o.parent().find("a").toggle(),i.val()||(i.val(woocommerce_admin_meta_boxes_order.default_country).change(),n.val(woocommerce_admin_meta_boxes_order.default_state).change()),a.show();var c=d?"order_edit_billing_address_click":"order_edit_shipping_address_click";window.wcTracks.recordEvent(c,{order_id:woocommerce_admin_meta_boxes.post_id,status:p("#order_status").val()})},change_customer_user:function(){p("#_billing_country").val()||(p("a.edit_address").click(),w.load_billing(!0),w.load_shipping(!0))},load_billing:function(e){if(!0===e||window.confirm(woocommerce_admin_meta_boxes.load_billing)){var o=p("#customer_user").val();if(!o)return window.alert(woocommerce_admin_meta_boxes.no_customer_selected),!1;var t={user_id:o,action:"woocommerce_get_customer_details",security:woocommerce_admin_meta_boxes.get_customer_details_nonce};p(this).closest("div.edit_address").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),p.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:t,type:"POST",success:function(e){e&&e.billing&&p.each(e.billing,function(e,o){p(":input#_billing_"+e).val(o).change()}),p("div.edit_address").unblock()}})}return!1},load_shipping:function(e){if(!0===e||window.confirm(woocommerce_admin_meta_boxes.load_shipping)){var o=p("#customer_user").val();if(!o)return window.alert(woocommerce_admin_meta_boxes.no_customer_selected),!1;var t={user_id:o,action:"woocommerce_get_customer_details",security:woocommerce_admin_meta_boxes.get_customer_details_nonce};p(this).closest("div.edit_address").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),p.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:t,type:"POST",success:function(e){e&&e.billing&&p.each(e.shipping,function(e,o){p(":input#_shipping_"+e).val(o).change()}),p("div.edit_address").unblock()}})}return!1},copy_billing_to_shipping:function(){return window.confirm(woocommerce_admin_meta_boxes.copy_billing)&&p('.order_data_column :input[name^="_billing_"]').each(function(){var e=p(this).attr("name");e=e.replace("_billing_","_shipping_"),p(":input#"+e).val(p(this).val()).change()}),!1}},d={init:function(){this.stupidtable.init(),p("#woocommerce-order-items").on("click","button.add-line-item",this.add_line_item).on("click","button.add-coupon",this.add_coupon).on("click","a.remove-coupon",this.remove_coupon).on("click","button.refund-items",this.refund_items).on("click",".cancel-action",this.cancel).on("click",".refund-actions .cancel-action",this.track_cancel).on("click","button.add-order-item",this.add_item).on("click","button.add-order-fee",this.add_fee).on("click","button.add-order-shipping",this.add_shipping).on("click","button.add-order-tax",this.add_tax).on("click","button.save-action",this.save_line_items).on("click","a.delete-order-tax",this.delete_tax).on("click","button.calculate-action",this.recalculate).on("click","a.edit-order-item",this.edit_item).on("click","a.delete-order-item",this.delete_item).on("click",".delete_refund",this.refunds.delete_refund).on("click","button.do-api-refund, button.do-manual-refund",this.refunds.do_refund).on("change",".refund input.refund_line_total, .refund input.refund_line_tax",this.refunds.input_changed).on("change keyup",".wc-order-refund-items #refund_amount",this.refunds.amount_changed).on("change","input.refund_order_item_qty",this.refunds.refund_quantity_changed).on("change","input.quantity",this.quantity_changed).on("keyup change",".split-input :input",function(){var e=p(this).parent().prev().find(":input");e&&(""===e.val()||e.is(".match-total"))&&e.val(p(this).val()).addClass("match-total")}).on("keyup",".split-input :input",function(){p(this).removeClass("match-total")}).on("click","button.add_order_item_meta",this.item_meta.add).on("click","button.remove_order_item_meta",this.item_meta.remove).on("wc_order_items_reload",this.reload_items).on("wc_order_items_reloaded",this.reloaded_items),p(document.body).on("wc_backbone_modal_loaded",this.backbone.init).on("wc_backbone_modal_response",this.backbone.response)},block:function(){p("#woocommerce-order-items").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){p("#woocommerce-order-items").unblock()},reload_items:function(){var e={order_id:woocommerce_admin_meta_boxes.post_id,action:"woocommerce_load_order_items",security:woocommerce_admin_meta_boxes.order_item_nonce};d.block(),p.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:e,type:"POST",success:function(e){p("#woocommerce-order-items").find(".inside").empty(),p("#woocommerce-order-items").find(".inside").append(e),d.reloaded_items(),d.unblock()}})},reloaded_items:function(){w.init_tiptip(),d.stupidtable.init()},quantity_changed:function(){var d=p(this).closest("tr.item"),c=p(this).val(),_=p(this).attr("data-qty"),e=p("input.line_total",d),o=p("input.line_subtotal",d),t=accounting.unformat(e.attr("data-total"),woocommerce_admin.mon_decimal_point)/_;e.val(parseFloat(accounting.formatNumber(t*c,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point));var a=accounting.unformat(o.attr("data-subtotal"),woocommerce_admin.mon_decimal_point)/_;o.val(parseFloat(accounting.formatNumber(a*c,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point)),p("input.line_tax",d).each(function(){var e=p(this),o=e.data("tax_id"),t=accounting.unformat(e.attr("data-total_tax"),woocommerce_admin.mon_decimal_point)/_,a=p('input.line_subtotal_tax[data-tax_id="'+o+'"]',d),r=accounting.unformat(a.attr("data-subtotal_tax"),woocommerce_admin.mon_decimal_point)/_,i="yes"===woocommerce_admin_meta_boxes.round_at_subtotal,n=woocommerce_admin_meta_boxes[i?"rounding_precision":"currency_format_num_decimals"];0<t&&e.val(parseFloat(accounting.formatNumber(t*c,n,"")).toString().replace(".",woocommerce_admin.mon_decimal_point)),0<r&&a.val(parseFloat(accounting.formatNumber(r*c,n,"")).toString().replace(".",woocommerce_admin.mon_decimal_point))}),p(this).trigger("quantity_changed")},add_line_item:function(){return p("div.wc-order-add-item").slideDown(),p("div.wc-order-data-row-toggle").not("div.wc-order-add-item").slideUp(),window.wcTracks.recordEvent("order_edit_add_items_click",{order_id:woocommerce_admin_meta_boxes.post_id,status:p("#order_status").val()}),!1},add_coupon:function(){window.wcTracks.recordEvent("order_edit_add_coupon_click",{order_id:woocommerce_admin_meta_boxes.post_id,status:p("#order_status").val()});var e=window.prompt(woocommerce_admin_meta_boxes.i18n_apply_coupon);if(null==e)window.wcTracks.recordEvent("order_edit_add_coupon_cancel",{order_id:woocommerce_admin_meta_boxes.post_id,status:p("#order_status").val()});else{d.block();var o=p("#customer_user").val(),t=p("#_billing_email").val(),a=p.extend({},d.get_taxable_address(),{action:"woocommerce_add_coupon_discount",dataType:"json",order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce,coupon:e,user_id:o,user_email:t});p.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:a,type:"POST",success:function(e){e.success?(p("#woocommerce-order-items").find(".inside").empty(),p("#woocommerce-order-items").find(".inside").append(e.data.html),d.reloaded_items(),d.unblock()):window.alert(e.data.error),d.unblock()},complete:function(){window.wcTracks.recordEvent("order_edit_added_coupon",{order_id:a.order_id,status:p("#order_status").val()})}})}return!1},remove_coupon:function(){var e=p(this);d.block();var o=p.extend({},d.get_taxable_address(),{action:"woocommerce_remove_order_coupon",dataType:"json",order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce,coupon:e.data("code")});p.post(woocommerce_admin_meta_boxes.ajax_url,o,function(e){e.success?(p("#woocommerce-order-items").find(".inside").empty(),p("#woocommerce-order-items").find(".inside").append(e.data.html),d.reloaded_items(),d.unblock()):window.alert(e.data.error),d.unblock()})},refund_items:function(){return p("div.wc-order-refund-items").slideDown(),p("div.wc-order-data-row-toggle").not("div.wc-order-refund-items").slideUp(),p("div.wc-order-totals-items").slideUp(),p("#woocommerce-order-items").find("div.refund").show(),p(".wc-order-edit-line-item .wc-order-edit-line-item-actions").hide(),window.wcTracks.recordEvent("order_edit_refund_button_click",{order_id:woocommerce_admin_meta_boxes.post_id,status:p("#order_status").val()}),!1},cancel:function(){return p("div.wc-order-data-row-toggle").not("div.wc-order-bulk-actions").slideUp(),p("div.wc-order-bulk-actions").slideDown(),p("div.wc-order-totals-items").slideDown(),p("#woocommerce-order-items").find("div.refund").hide(),p(".wc-order-edit-line-item .wc-order-edit-line-item-actions").show(),"true"===p(this).attr("data-reload")&&d.reload_items(),window.wcTracks.recordEvent("order_edit_add_items_cancelled",{order_id:woocommerce_admin_meta_boxes.post_id,status:p("#order_status").val()}),!1},track_cancel:function(){window.wcTracks.recordEvent("order_edit_refund_cancel",{order_id:woocommerce_admin_meta_boxes.post_id,status:p("#order_status").val()})},add_item:function(){return p(this).WCBackboneModal({template:"wc-modal-add-products"}),!1},add_fee:function(){window.wcTracks.recordEvent("order_edit_add_fee_click",{order_id:woocommerce_admin_meta_boxes.post_id,status:p("#order_status").val()});var e=window.prompt(woocommerce_admin_meta_boxes.i18n_add_fee);if(null==e)window.wcTracks.recordEvent("order_edit_add_fee_cancel",{order_id:woocommerce_admin_meta_boxes.post_id,status:p("#order_status").val()});else{d.block();var o=p.extend({},d.get_taxable_address(),{action:"woocommerce_add_order_fee",dataType:"json",order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce,amount:e});p.post(woocommerce_admin_meta_boxes.ajax_url,o,function(e){e.success?(p("#woocommerce-order-items").find(".inside").empty(),p("#woocommerce-order-items").find(".inside").append(e.data.html),d.reloaded_items(),d.unblock(),window.wcTracks.recordEvent("order_edit_added_fee",{order_id:o.post_id,status:p("#order_status").val()})):window.alert(e.data.error),d.unblock()})}return!1},add_shipping:function(){d.block();var o={action:"woocommerce_add_order_shipping",order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce,dataType:"json"};return p.post(woocommerce_admin_meta_boxes.ajax_url,o,function(e){e.success?(p("table.woocommerce_order_items tbody#order_shipping_line_items").append(e.data.html),window.wcTracks.recordEvent("order_edit_add_shipping",{order_id:o.post_id,status:p("#order_status").val()})):window.alert(e.data.error),d.unblock()}),!1},add_tax:function(){return p(this).WCBackboneModal({template:"wc-modal-add-tax"}),!1},edit_item:function(){return p(this).closest("tr").find(".view").hide(),p(this).closest("tr").find(".edit").show(),p(this).hide(),p("button.add-line-item").click(),p("button.cancel-action").attr("data-reload",!0),window.wcTracks.recordEvent("order_edit_edit_item_click",{order_id:woocommerce_admin_meta_boxes.post_id,status:p("#order_status").val()}),!1},delete_item:function(){if(window.confirm(woocommerce_admin_meta_boxes.remove_item_notice)){var e=p(this).closest("tr.item, tr.fee, tr.shipping").attr("data-order_item_id");d.block();var o=p.extend({},d.get_taxable_address(),{order_id:woocommerce_admin_meta_boxes.post_id,order_item_ids:e,action:"woocommerce_remove_order_item",security:woocommerce_admin_meta_boxes.order_item_nonce});"true"===p("button.cancel-action").attr("data-reload")&&(o.items=p("table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]").serialize()),p.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:o,type:"POST",success:function(e){e.success?(p("#woocommerce-order-items").find(".inside").empty(),p("#woocommerce-order-items").find(".inside").append(e.data.html),e.data.notes_html&&(p("ul.order_notes").empty(),p("ul.order_notes").append(p(e.data.notes_html).find("li"))),d.reloaded_items(),d.unblock()):window.alert(e.data.error),d.unblock()},complete:function(){window.wcTracks.recordEvent("order_edit_remove_item",{order_id:o.post_id,status:p("#order_status").val()})}})}return!1},delete_tax:function(){if(window.confirm(woocommerce_admin_meta_boxes.i18n_delete_tax)){d.block();var e={action:"woocommerce_remove_order_tax",rate_id:p(this).attr("data-rate_id"),order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};p.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:e,type:"POST",success:function(e){e.success?(p("#woocommerce-order-items").find(".inside").empty(),p("#woocommerce-order-items").find(".inside").append(e.data.html),d.reloaded_items(),d.unblock()):window.alert(e.data.error),d.unblock()},complete:function(){window.wcTracks.recordEvent("order_edit_delete_tax",{order_id:e.order_id,status:p("#order_status").val()})}})}else window.wcTracks.recordEvent("order_edit_delete_tax_cancel",{order_id:woocommerce_admin_meta_boxes.post_id,status:p("#order_status").val()});return!1},get_taxable_address:function(){var e="",o="",t="",a="";return"shipping"===woocommerce_admin_meta_boxes.tax_based_on&&(e=p("#_shipping_country").val(),o=p("#_shipping_state").val(),t=p("#_shipping_postcode").val(),a=p("#_shipping_city").val()),"billing"!==woocommerce_admin_meta_boxes.tax_based_on&&e||(e=p("#_billing_country").val(),o=p("#_billing_state").val(),t=p("#_billing_postcode").val(),a=p("#_billing_city").val()),{country:e,state:o,postcode:t,city:a}},recalculate:function(){if(window.confirm(woocommerce_admin_meta_boxes.calc_totals)){d.block();var o=p.extend({},d.get_taxable_address(),{action:"woocommerce_calc_line_taxes",order_id:woocommerce_admin_meta_boxes.post_id,items:p("table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]").serialize(),security:woocommerce_admin_meta_boxes.calc_totals_nonce});p(document.body).trigger("order-totals-recalculate-before",o),p.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:o,type:"POST",success:function(e){p("#woocommerce-order-items").find(".inside").empty(),p("#woocommerce-order-items").find(".inside").append(e),d.reloaded_items(),d.unblock(),p(document.body).trigger("order-totals-recalculate-success",e)},complete:function(e){p(document.body).trigger("order-totals-recalculate-complete",e),window.wcTracks.recordEvent("order_edit_recalc_totals",{order_id:o.post_id,OK_cancel:"OK",status:p("#order_status").val()})}})}else window.wcTracks.recordEvent("order_edit_recalc_totals",{order_id:woocommerce_admin_meta_boxes.post_id,OK_cancel:"cancel",status:p("#order_status").val()});return!1},save_line_items:function(){var e={order_id:woocommerce_admin_meta_boxes.post_id,items:p("table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]").serialize(),action:"woocommerce_save_order_items",security:woocommerce_admin_meta_boxes.order_item_nonce};return d.block(),p.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:e,type:"POST",success:function(e){e.success?(p("#woocommerce-order-items").find(".inside").empty(),p("#woocommerce-order-items").find(".inside").append(e.data.html),e.data.notes_html&&(p("ul.order_notes").empty(),p("ul.order_notes").append(p(e.data.notes_html).find("li"))),d.reloaded_items(),d.unblock()):(d.unblock(),window.alert(e.data.error))},complete:function(){window.wcTracks.recordEvent("order_edit_save_line_items",{order_id:e.post_id,status:p("#order_status").val()})}}),p(this).trigger("items_saved"),!1},refunds:{do_refund:function(){if(d.block(),window.confirm(woocommerce_admin_meta_boxes.i18n_do_refund)){var e=p("input#refund_amount").val(),o=p("input#refund_reason").val(),t=p("input#refunded_amount").val(),a={},r={},i={};p(".refund input.refund_order_item_qty").each(function(e,o){p(o).closest("tr").data("order_item_id")&&o.value&&(a[p(o).closest("tr").data("order_item_id")]=o.value)}),p(".refund input.refund_line_total").each(function(e,o){p(o).closest("tr").data("order_item_id")&&(r[p(o).closest("tr").data("order_item_id")]=accounting.unformat(o.value,woocommerce_admin.mon_decimal_point))}),p(".refund input.refund_line_tax").each(function(e,o){if(p(o).closest("tr").data("order_item_id")){var t=p(o).data("tax_id");i[p(o).closest("tr").data("order_item_id")]||(i[p(o).closest("tr").data("order_item_id")]={}),i[p(o).closest("tr").data("order_item_id")][t]=accounting.unformat(o.value,woocommerce_admin.mon_decimal_point)}});var n={action:"woocommerce_refund_line_items",order_id:woocommerce_admin_meta_boxes.post_id,refund_amount:e,refunded_amount:t,refund_reason:o,line_item_qtys:JSON.stringify(a,null,""),line_item_totals:JSON.stringify(r,null,""),line_item_tax_totals:JSON.stringify(i,null,""),api_refund:p(this).is(".do-api-refund"),restock_refunded_items:p("#restock_refunded_items:checked").length?"true":"false",security:woocommerce_admin_meta_boxes.order_item_nonce};p.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:n,type:"POST",success:function(e){!0===e.success?window.location.reload():(window.alert(e.data.error),d.reload_items(),d.unblock())},complete:function(){window.wcTracks.recordEvent("order_edit_refunded",{order_id:n.order_id,status:p("#order_status").val(),api_refund:n.api_refund,has_reason:Boolean(n.refund_reason.length),restock:"true"===n.restock_refunded_items})}})}else d.unblock()},delete_refund:function(){if(window.confirm(woocommerce_admin_meta_boxes.i18n_delete_refund)){var e=p(this).closest("tr.refund").attr("data-order_refund_id");d.block();var o={action:"woocommerce_delete_refund",refund_id:e,security:woocommerce_admin_meta_boxes.order_item_nonce};p.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:o,type:"POST",success:function(){d.reload_items()}})}return!1},input_changed:function(){var t=0;p(".woocommerce_order_items").find("tr.item, tr.fee, tr.shipping").each(function(){p(this).find(".refund input:not(.refund_order_item_qty)").each(function(e,o){t+=parseFloat(accounting.unformat(p(o).val()||0,woocommerce_admin.mon_decimal_point))})}),p("#refund_amount").val(accounting.formatNumber(t,woocommerce_admin_meta_boxes.currency_format_num_decimals,"",woocommerce_admin.mon_decimal_point)).change()},amount_changed:function(){var e=accounting.unformat(p(this).val(),woocommerce_admin.mon_decimal_point);p("button .wc-order-refund-amount .amount").text(accounting.formatMoney(e,{symbol:woocommerce_admin_meta_boxes.currency_format_symbol,decimal:woocommerce_admin_meta_boxes.currency_format_decimal_sep,thousand:woocommerce_admin_meta_boxes.currency_format_thousand_sep,precision:woocommerce_admin_meta_boxes.currency_format_num_decimals,format:woocommerce_admin_meta_boxes.currency_format}))},refund_quantity_changed:function(){var n=p(this).closest("tr.item"),d=n.find("input.quantity").val(),c=p(this).val(),e=p("input.line_total",n),o=p("input.refund_line_total",n),t=accounting.unformat(e.attr("data-total"),woocommerce_admin.mon_decimal_point)/d;o.val(parseFloat(accounting.formatNumber(t*c,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point)).change(),p(".refund_line_tax",n).each(function(){var e=p(this),o=e.data("tax_id"),t=p('input.line_tax[data-tax_id="'+o+'"]',n),a=accounting.unformat(t.data("total_tax"),woocommerce_admin.mon_decimal_point)/d;if(0<a){var r="yes"===woocommerce_admin_meta_boxes.round_at_subtotal,i=woocommerce_admin_meta_boxes[r?"rounding_precision":"currency_format_num_decimals"];e.val(parseFloat(accounting.formatNumber(a*c,i,"")).toString().replace(".",woocommerce_admin.mon_decimal_point)).change()}else e.val(0).change()}),0<c?p("#restock_refunded_items").closest("tr").show():(p("#restock_refunded_items").closest("tr").hide(),p(".woocommerce_order_items input.refund_order_item_qty").each(function(){0<p(this).val()&&p("#restock_refunded_items").closest("tr").show()})),p(this).trigger("refund_quantity_changed")}},item_meta:{add:function(){var e=p(this).closest("tr.item, tr.shipping"),o=e.find("tbody.meta_items"),t=o.find("tr").length+1,a='<tr data-meta_id="0"><td><input type="text" maxlength="255" placeholder="'+woocommerce_admin_meta_boxes_order.placeholder_name+'" name="meta_key['+e.attr("data-order_item_id")+"][new-"+t+']" /><textarea placeholder="'+woocommerce_admin_meta_boxes_order.placeholder_value+'" name="meta_value['+e.attr("data-order_item_id")+"][new-"+t+']"></textarea></td><td width="1%"><button class="remove_order_item_meta button">&times;</button></td></tr>';return o.append(a),!1},remove:function(){if(window.confirm(woocommerce_admin_meta_boxes.remove_item_meta)){var e=p(this).closest("tr");e.find(":input").val(""),e.hide()}return!1}},backbone:{init:function(e,o){"wc-modal-add-products"===o&&(p(document.body).trigger("wc-enhanced-select-init"),p(this).on("change",".wc-product-search",function(){if(p(this).closest("tr").is(":last-child")){var e=p(this).closest("table.widefat").find("tbody"),o=e.find("tr").length,t=e.data("row").replace(/\[0\]/g,"["+o+"]");e.append("<tr>"+t+"</tr>"),p(document.body).trigger("wc-enhanced-select-init")}}))},response:function(e,o,t){if("wc-modal-add-tax"===o){var a=t.add_order_tax,r="";t.manual_tax_rate_id&&(r=t.manual_tax_rate_id),d.backbone.add_tax(a,r)}if("wc-modal-add-products"===o){var i=p(this).find("table.widefat").find("tbody").find("tr"),n=[];return p(i).each(function(){var e=p(this).find(':input[name="item_id"]').val(),o=p(this).find(':input[name="item_qty"]').val();n.push({id:e,qty:o||1})}),d.backbone.add_items(n)}},add_items:function(e){d.block();var o={action:"woocommerce_add_order_item",order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce,data:e};"true"===p("button.cancel-action").attr("data-reload")&&(o.items=p("table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]").serialize()),p.ajax({type:"POST",url:woocommerce_admin_meta_boxes.ajax_url,data:o,success:function(e){e.success?(p("#woocommerce-order-items").find(".inside").empty(),p("#woocommerce-order-items").find(".inside").append(e.data.html),e.data.notes_html&&(p("ul.order_notes").empty(),p("ul.order_notes").append(p(e.data.notes_html).find("li"))),d.reloaded_items(),d.unblock()):(d.unblock(),window.alert(e.data.error))},complete:function(){window.wcTracks.recordEvent("order_edit_add_products",{order_id:o.post_id,status:p("#order_status").val()})},dataType:"json"})},add_tax:function(e,o){if(o&&(e=o),!e)return!1;var t=p(".order-tax-id").map(function(){return p(this).val()}).get();if(-1===p.inArray(e,t)){d.block();var a={action:"woocommerce_add_order_tax",rate_id:e,order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};p.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:a,dataType:"json",type:"POST",success:function(e){e.success?(p("#woocommerce-order-items").find(".inside").empty(),p("#woocommerce-order-items").find(".inside").append(e.data.html),d.reloaded_items()):window.alert(e.data.error),d.unblock()},complete:function(){window.wcTracks.recordEvent("order_edit_add_tax",{order_id:a.post_id,status:p("#order_status").val()})}})}else window.alert(woocommerce_admin_meta_boxes.i18n_tax_rate_already_exists)}},stupidtable:{init:function(){p(".woocommerce_order_items").stupidtable(),p(".woocommerce_order_items").on("aftertablesort",this.add_arrows)},add_arrows:function(e,o){var t=p(this).find("th"),a="asc"===o.direction?"&uarr;":"&darr;",r=o.column;t.find(".wc-arrow").remove(),t.eq(r).append('<span class="wc-arrow">'+a+"</span>")}}},e={init:function(){p("#woocommerce-order-notes").on("click","button.add_note",this.add_order_note).on("click","a.delete_note",this.delete_order_note)},add_order_note:function(){if(p("textarea#add_order_note").val()){p("#woocommerce-order-notes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var o={action:"woocommerce_add_order_note",post_id:woocommerce_admin_meta_boxes.post_id,note:p("textarea#add_order_note").val(),note_type:p("select#order_note_type").val(),security:woocommerce_admin_meta_boxes.add_order_note_nonce};return p.post(woocommerce_admin_meta_boxes.ajax_url,o,function(e){p("ul.order_notes").prepend(e),p("#woocommerce-order-notes").unblock(),p("#add_order_note").val(""),window.wcTracks.recordEvent("order_edit_add_order_note",{order_id:o.post_id,note_type:o.note_type||"private",status:p("#order_status").val()})}),!1}},delete_order_note:function(){if(window.confirm(woocommerce_admin_meta_boxes.i18n_delete_note)){var e=p(this).closest("li.note");p(e).block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var o={action:"woocommerce_delete_order_note",note_id:p(e).attr("rel"),security:woocommerce_admin_meta_boxes.delete_order_note_nonce};p.post(woocommerce_admin_meta_boxes.ajax_url,o,function(){p(e).remove()})}return!1}},o={init:function(){p(".order_download_permissions").on("click","button.grant_access",this.grant_access).on("click","button.revoke_access",this.revoke_access).on("click","#copy-download-link",this.copy_link).on("aftercopy","#copy-download-link",this.copy_success).on("aftercopyfailure","#copy-download-link",this.copy_fail)},grant_access:function(){var e=p("#grant_access_id").val();if(e){p(".order_download_permissions").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var o={action:"woocommerce_grant_access_to_download",product_ids:e,loop:p(".order_download_permissions .wc-metabox").length,order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.grant_access_nonce};return p.post(woocommerce_admin_meta_boxes.ajax_url,o,function(e){e?p(".order_download_permissions .wc-metaboxes").append(e):window.alert(woocommerce_admin_meta_boxes.i18n_download_permission_fail),p(document.body).trigger("wc-init-datepickers"),p("#grant_access_id").val("").change(),p(".order_download_permissions").unblock()}),!1}},revoke_access:function(){if(window.confirm(woocommerce_admin_meta_boxes.i18n_permission_revoke)){var e=p(this).parent().parent(),o=p(this).attr("rel").split(",")[0],t=p(this).attr("rel").split(",")[1],a=p(this).data("permission_id");if(0<o){p(e).block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var r={action:"woocommerce_revoke_access_to_download",product_id:o,download_id:t,permission_id:a,order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.revoke_access_nonce};p.post(woocommerce_admin_meta_boxes.ajax_url,r,function(){p(e).fadeOut("300",function(){p(e).remove()})})}else p(e).fadeOut("300",function(){p(e).remove()})}return!1},copy_link:function(e){wcClearClipboard(),wcSetClipboard(p(this).attr("href"),p(this)),e.preventDefault()},copy_success:function(){p(this).tipTip({attribute:"data-tip",activation:"focus",fadeIn:50,fadeOut:50,delay:0}).focus()},copy_fail:function(){p(this).tipTip({attribute:"data-tip-failed",activation:"focus",fadeIn:50,fadeOut:50,delay:0}).focus()}};w.init(),d.init(),e.init(),o.init()});