function generateLabel(orderId){var csrf=document.querySelector("meta[name=csrf-token]").content;fetch("api/bridge.php?target=shipping",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","X-CSRF-Token":csrf},body:"target=shipping&endpoint=create_label&data[order_id]="+orderId+"&_csrf="+csrf}).then(r=>r.json()).then(d=>{if(d.tracking_pin){alert("Label created: "+d.tracking_pin);location.reload();}else{alert(d.error||"Failed");}});}
function linkTracking(orderId){var ref=document.getElementById("tracking-input").value;if(!ref)return;var csrf=document.querySelector("meta[name=csrf-token]").content;fetch("index.php",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:"system_action=modify&entity=order_fulfillment&id="+orderId+"&data[tracking_ref]="+encodeURIComponent(ref)+"&data[tracking_status]=in_transit&_csrf="+csrf}).then(r=>r.json()).then(d=>{if(d.success)location.reload();});}
