(()=>{function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}document.addEventListener("DOMContentLoaded",function(){var t=PayPalCommerceGatewayOrderTrackingInfo;if("undefined"==typeof PayPalCommerceGatewayOrderTrackingInfo||e(PayPalCommerceGatewayOrderTrackingInfo)){var n,r=document.getElementById("include-all-items"),a=document.querySelector(".ppcp-tracking-capture_id"),c=document.querySelector(".ppcp-tracking-order_id"),o=document.querySelector(".ppcp-tracking-carrier"),i=document.querySelector(".ppcp-tracking-carrier_name_other");jQuery(document).on("click",".submit_tracking_info",function(){var e=document.querySelector(".ppcp-tracking-tracking_number"),n=document.querySelector(".ppcp-tracking-status"),u=document.querySelector(".submit_tracking_info"),l=document.querySelector(".ppcp-tracking-items"),p=document.querySelector(".ppcp-tracking-no-shipments"),d=null!=r&&r.checked||!l?0:Array.from(l.selectedOptions).map(function(e){return e.value});s(),fetch(t.ajax.tracking_info.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({nonce:t.ajax.tracking_info.nonce,capture_id:a?a.value:null,tracking_number:e?e.value:null,status:n?n.value:null,carrier:o?o.value:null,carrier_name_other:i?i.value:null,order_id:c?c.value:null,items:d})}).then(function(e){return e.json()}).then(function(t){if(s(),!t.success||!t.data.shipment)throw jQuery("<p class='error tracking-info-message'>"+t.data.message+"</p>").insertAfter(u),setTimeout(function(){return jQuery(".tracking-info-message").remove()},3e3),u.removeAttribute("disabled"),console.error(t),Error(t.data.message);jQuery("<p class='success tracking-info-message'>"+t.data.message+"</p>").insertAfter(u),setTimeout(function(){return jQuery(".tracking-info-message").remove()},3e3),jQuery(t.data.shipment).appendTo("#ppcp_order-tracking .ppcp-tracking-column.shipments"),p&&p.parentNode.removeChild(p),e.value=""})}),jQuery(document).on("click",".update_shipment",function(e){var n=e.target,r=n.parentNode.parentNode,o=r.querySelector(".ppcp-shipment-status"),i=r.querySelector(".ppcp-shipment-tacking_number"),u=r.querySelector(".ppcp-shipment-carrier"),l=r.querySelector(".ppcp-shipment-carrier-other");s(),fetch(t.ajax.tracking_info.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({nonce:t.ajax.tracking_info.nonce,capture_id:a?a.value:null,tracking_number:i?i.value:null,status:o?o.value:null,carrier:u?u.value:null,carrier_name_other:l?l.value:null,order_id:c?c.value:null,action:"update"})}).then(function(e){return e.json()}).then(function(e){if(s(),!e.success)throw jQuery("<p class='error tracking-info-message'>"+e.data.message+"</p>").insertAfter(n),setTimeout(function(){return jQuery(".tracking-info-message").remove()},3e3),console.error(e),Error(e.data.message);jQuery("<p class='success tracking-info-message'>"+e.data.message+"</p>").insertAfter(n),setTimeout(function(){return jQuery(".tracking-info-message").remove()},3e3)})}),n=document.getElementById("items-select-container"),null==r||r.addEventListener("change",function(){n.style.display=r.checked?"none":"block"}),jQuery(document).on("click",".ppcp-shipment-header",function(e){var t=e.target.closest(".ppcp-shipment"),n=t.querySelector(".ppcp-shipment-info");t.classList.toggle("active"),t.classList.toggle("closed"),n.classList.toggle("hidden")}),jQuery(document).on("change",".ppcp-shipment-status",function(e){var t=e.target,n=t.closest(".ppcp-shipment").querySelector(".update_shipment");t.value,n.classList.remove("button-disabled")}),jQuery(o).on("change",function(){var e=i.parentNode;"OTHER"===o.value?e.classList.remove("hidden"):e.classList.contains("hidden")||e.classList.add("hidden")})}else console.error("tracking cannot be set.");function s(){var e=document.querySelector(".ppcp-tracking-loader");e&&("none"===e.style.display||""===e.style.display?e.style.display="block":e.style.display="none")}})})();