var f=(x,i,o)=>new Promise((e,l)=>{var n=a=>{try{d(o.next(a))}catch(u){l(u)}},m=a=>{try{d(o.throw(a))}catch(u){l(u)}},d=a=>a.done?e(a.value):Promise.resolve(a.value).then(n,m);d((o=o.apply(x,i)).next())});import{b6 as c,c0 as D}from"./bootstrap-Bqxdt4iG.js";import{u as E}from"./data-refresh-BZ1_-6mk.js";import{u as O}from"./tms-order-details-BRpXrzlt.js";import{_ as V}from"./order-detail-form.vue_vue_type_script_setup_true_lang-BvaeXkpr.js";import{S as R}from"./index-D0CahMPl.js";import{T as j}from"./index-axp3BSAN.js";import{a1 as U,L as v,ai as $,aj as _,a9 as p,ak as A,ap as h,p as T,az as w,ay as g,ax as q}from"../jse/index-index-BUJ_4tQs.js";import{u as z}from"./use-drawer-CLDmRz16.js";import{t as G}from"./tms-order-details-D5ZqC9Ar.js";const H={key:0,class:"flex h-40 items-center justify-center"},J={key:1},K={class:"mb-4 flex items-center gap-2"},M={class:"text-gray-400"},P={class:"font-medium"},Q={key:2,class:"py-8 text-center text-gray-500"},le=U({__name:"order-detail-edit-drawer",setup(x){const i=O(),o=E(),e=v(null),l=v(""),n=v(!1),m=v(!1),d=t=>{switch(t){case"AIR":return"purple";case"LAND":return"green";case"SEA":return"blue";default:return"default"}},a=()=>e.value?e.value.transportType==="LAND"&&"landDetail"in e.value?e.value.landDetail:"freightDetail"in e.value?e.value.freightDetail:null:null,u=t=>f(null,null,function*(){n.value=!0;try{e.value=yield i.getDetail(t)}catch(s){console.error("Failed to load detail:",s),D.error(c("page.tms.orders.message.loadError"))}finally{n.value=!1}}),F=t=>f(null,null,function*(){if(e.value){m.value=!0;try{yield e.value.transportType==="LAND"?i.updateLandDetail(e.value.id,t):i.updateFreightDetail(e.value.id,t),o.invalidateTmsOrderDetails(),D.success(c("page.tms.orders.message.detailUpdated")),y.close()}catch(s){console.error("Failed to update detail:",s),D.error(c("page.tms.orders.message.detailUpdateError"))}finally{m.value=!1}}}),L=()=>{y.close()},[I,y]=z({title:c("page.tms.orderDetails.drawer.editTitle"),footer:!1,onOpenChange:t=>f(null,null,function*(){var s;if(t){const r=y.getData();r!=null&&r.orderDetailId&&(l.value=(s=r.customerId)!=null?s:"",yield u(r.orderDetailId))}}),onClosed:()=>{e.value=null,l.value=""}});return(t,s)=>(_(),$(p(I),{class:"w-[1100px]"},{default:A(()=>{var r,S,b,N;return[n.value?(_(),h("div",H,[T(p(R))])):e.value?(_(),h("div",J,[w("div",K,[w("span",M,"#"+g((r=e.value)==null?void 0:r.seqNo),1),T(p(j),{color:d((b=(S=e.value)==null?void 0:S.transportType)!=null?b:"")},{default:A(()=>{var k;return[q(g((k=p(G).find(B=>{var C;return B.value===((C=e.value)==null?void 0:C.transportType)}))==null?void 0:k.label),1)]}),_:1},8,["color"]),w("span",P,g((N=e.value)==null?void 0:N.detailNo),1)]),T(V,{"transport-type":e.value.transportType,"customer-id":l.value,detail:a(),mode:"edit",onSubmit:F,onCancel:L},null,8,["transport-type","customer-id","detail"])])):(_(),h("div",Q,g(p(c)("page.tms.orders.detail.notFound")),1))]}),_:1}))}});export{le as _};
