var I=(f,E,l)=>new Promise((F,g)=>{var N=i=>{try{c(l.next(i))}catch(b){g(b)}},D=i=>{try{c(l.throw(i))}catch(b){g(b)}},c=i=>i.done?F(i.value):Promise.resolve(i.value).then(N,D);c((l=l.apply(f,E)).next())});import{by as G,b7 as J,aw as S,I as R,b6 as a,c0 as V}from"./bootstrap-Bqxdt4iG.js";import{u as K}from"./useRoleAccess-rNIDgdat.js";import{u as O}from"./data-refresh-BZ1_-6mk.js";import{u as P}from"./tms-drivers-CG8odbgf.js";import{_ as Q}from"./driver-edit-drawer.vue_vue_type_script_setup_true_lang-CoO9BExs.js";import{C as W}from"./index-0OckuOQU.js";import{D as p}from"./index--N1ITuK7.js";import{S as X}from"./index-D0CahMPl.js";import{a1 as Y,E as M,L as x,U as j,aa as Z,bH as ee,ap as B,aj as u,p as r,ak as s,az as C,ai as w,an as v,a9 as e,ax as n,ay as o,F as ae,aR as te}from"../jse/index-index-BUJ_4tQs.js";import{u as re}from"./use-tabs-C7aNnvnZ.js";import{u as se}from"./use-drawer-CLDmRz16.js";import oe from"./index-DL4Zx5Zk.js";const le={class:"mb-4 flex gap-2"},ie={class:"mb-6"},ne={class:"text-xl font-semibold"},de={key:1,class:"text-center text-gray-500"},xe=Y({name:"DriverDetail",__name:"driver-detail",props:{driverId:{default:""},mode:{default:"page"}},setup(f,{expose:E}){const l=f,F=G(),g=J(),{closeCurrentTab:N}=re(),D=P(),c=O(),{canDelete:i,canEdit:b}=K(),z=b("drivers"),A=i("drivers"),m=M(()=>l.driverId||F.params.id),y=x(!1),t=x(null),h=x(!1),T=x(!0),k=M(()=>l.mode==="drawer"?1:2),[H,L]=se({connectedComponent:Q});j(()=>c.driversVersion,()=>{m.value&&!h.value&&_()}),j(()=>l.driverId,d=>{d&&_()});const _=()=>I(null,null,function*(){if(m.value){y.value=!0;try{const d=yield D.getDetail(m.value);t.value=d}catch(d){V.error(a("page.tms.drivers.detail.notFound")),console.error("Failed to fetch driver detail:",d)}finally{y.value=!1}}}),U=()=>{L.setData({driverId:m.value}).open()},q=()=>I(null,null,function*(){if(t.value){h.value=!0;try{yield D.remove(t.value.id),c.invalidateDrivers(),V.success(a("page.modal.deleteSuccess")),l.mode==="page"&&(yield N(),g.push("/master-data/drivers/list"))}catch(d){V.error(a("page.modal.deleteFailed")),console.error("Failed to delete driver:",d)}finally{h.value=!1}}});return Z(()=>I(null,null,function*(){m.value&&(yield _())})),ee(()=>{if(T.value){T.value=!1;return}m.value&&!h.value&&_()}),E({refresh:_}),(d,$)=>(u(),B("div",{class:te(f.mode==="page"?"p-5":"")},[r(e(X),{spinning:y.value},{default:s(()=>[C("div",null,[C("div",le,[f.mode==="page"?(u(),w(e(S),{key:0,onClick:$[0]||($[0]=ue=>e(g).back())},{default:s(()=>[r(e(R),{icon:"lucide:arrow-left",class:"mr-1"}),n(" "+o(e(a)("common.back")),1)]),_:1})):v("",!0),t.value&&(e(z)||e(A))?(u(),B(ae,{key:1},[e(z)?(u(),w(e(S),{key:0,type:"primary",onClick:U},{default:s(()=>[r(e(R),{icon:"lucide:edit",class:"mr-1"}),n(" "+o(e(a)("page.table.actions.edit")),1)]),_:1})):v("",!0),e(A)?(u(),w(e(S),{key:1,danger:"",onClick:q},{default:s(()=>[r(e(R),{icon:"lucide:trash-2",class:"mr-1"}),n(" "+o(e(a)("page.table.actions.delete")),1)]),_:1})):v("",!0)],64)):v("",!0)]),t.value?(u(),w(e(W),{key:0},{default:s(()=>[C("div",ie,[C("h2",ne,o(t.value.name),1)]),r(e(oe),{orientation:"left","orientation-margin":0},{default:s(()=>[n(o(e(a)("page.tms.drivers.form.driverInfo")),1)]),_:1}),r(e(p),{column:k.value,bordered:"",size:"small"},{default:s(()=>[r(e(p).Item,{label:e(a)("page.tms.drivers.form.name"),span:k.value},{default:s(()=>[n(o(t.value.name||"-"),1)]),_:1},8,["label","span"]),r(e(p).Item,{label:e(a)("page.tms.drivers.form.icNo"),span:k.value},{default:s(()=>[n(o(t.value.icNo||"-"),1)]),_:1},8,["label","span"]),r(e(p).Item,{label:e(a)("page.tms.drivers.form.passportNo")},{default:s(()=>[n(o(t.value.passportNo||"-"),1)]),_:1},8,["label"]),r(e(p).Item,{label:e(a)("page.tms.drivers.form.passportExpiry")},{default:s(()=>[n(o(t.value.passportExpiry||"-"),1)]),_:1},8,["label"]),r(e(p).Item,{label:e(a)("page.tms.drivers.form.phone"),span:k.value},{default:s(()=>[n(o(t.value.phone||"-"),1)]),_:1},8,["label","span"])]),_:1},8,["column"])]),_:1})):v("",!0),!t.value&&!y.value?(u(),B("div",de,o(e(a)("page.tms.drivers.detail.notFound")),1)):v("",!0)])]),_:1},8,["spinning"]),r(e(H))],2))}});export{xe as _};
