import{y as U,A as j,U as H,b as q,m as G,z as J}from"./primevue-CfIk0_DY.js";import{u as K,b as O,s as c}from"./index-BxIwIJfy.js";import{R as Q}from"./ReportViewer-BNzhW7G2.js";import{u as W}from"./usePortailImpression-o_s9XGOt.js";import{a as u,o as X,b as w,c as Z,a7 as s,k as ee,p as te,d as n,t as d,v as a,l,f as D,j as C,y as f}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";import"./stimulsoft-B2-Y-rC1.js";import"./PDFButton-DhVJ6hNy.js";const oe={class:"max-w-5xl mx-auto"},ae={class:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",style:{"margin-bottom":"16px"}},ne={class:"text-gray-500",style:{"margin-top":"2px"}},se={class:"font-mono font-bold text-blue-700"},le={class:"font-semibold"},re={class:"flex gap-1"},xe={__name:"PortailClientBL",setup(ie){const{showError:g}=K(),{ouvrireReport:p,urlFichierRapport:F,nomFichierImpression:k,dataReport:$,apercuEnCours:B,telechargementEnCours:N,apercevoir:R,telecharger:T}=W(),v=f(()=>c.state.portailClientDb),y=f(()=>c.state.portailClientClient?.code_client),V=f(()=>c.state.portailClientToken),m=u(new Date().getFullYear()),z=u([new Date().getFullYear(),new Date().getFullYear()-1,new Date().getFullYear()-2]),i=u([]),h=u(!1),E=t=>t==null?"0,00":Number(t).toLocaleString("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2}),A=t=>{if(!t)return"—";const o=new Date(t);return isNaN(o)?"—":o.toLocaleDateString("fr-FR")},x=async()=>{if(!(!v.value||!y.value)){h.value=!0;try{const t=await O.get(`${c.lienApi}/portail-client/bl/${v.value}/${encodeURIComponent(y.value)}`,{params:{annee:m.value},headers:{Authorization:`Bearer ${V.value}`}});i.value=t.data||[]}catch{i.value=[]}finally{h.value=!1}}},L=async t=>{try{await R({type:"bl",nDoc:t.ndoc,libelleDocument:"Bon de livraison",fileName:`BL_${t.ndoc}`})}catch(o){g(o.message||"Erreur lors de l'apercu.")}},S=async t=>{try{await T({type:"bl",nDoc:t.ndoc,libelleDocument:"Bon de livraison",fileName:`BL_${t.ndoc}.pdf`})}catch(o){g(o.message||"Erreur lors du telechargement.")}};return X(x),(t,o)=>{const I=U,r=j,M=H,_=q,Y=J,b=G;return w(),Z("div",oe,[s(p)?(w(),ee(Q,{key:0,show:s(p),onClose:o[0]||(o[0]=e=>p.value=!1),data:s($),urlFichier:s(F),nomFichier:s(k)},null,8,["show","data","urlFichier","nomFichier"])):te("",!0),n("div",ae,[n("div",null,[o[2]||(o[2]=n("h1",{class:"text-2xl font-bold text-gray-800"},"Mes bons de livraison",-1)),n("p",ne,d(i.value.length)+" resultat(s)",1)]),a(I,{modelValue:m.value,"onUpdate:modelValue":o[1]||(o[1]=e=>m.value=e),options:z.value,onChange:x,size:"small",style:{"min-width":"100px"}},null,8,["modelValue","options"])]),a(Y,{value:i.value,loading:h.value,stripedRows:"",size:"small",paginator:"",rows:20,class:"bg-white rounded-xl shadow-sm overflow-hidden"},{empty:l(()=>[...o[3]||(o[3]=[n("div",{class:"text-center text-gray-400",style:{padding:"32px 0"}},[n("i",{class:"pi pi-truck text-3xl block",style:{"margin-bottom":"8px"}}),D(" Aucun bon de livraison pour cette annee. ")],-1)])]),default:l(()=>[a(r,{field:"ndoc",header:"N°",style:{width:"110px"}},{body:l(({data:e})=>[n("span",se,d(e.ndoc),1)]),_:1}),a(r,{field:"date",header:"Date",style:{width:"120px"}},{body:l(({data:e})=>[D(d(A(e.date)),1)]),_:1}),a(r,{field:"ttc_dh",header:"Montant TTC",style:{width:"150px"}},{body:l(({data:e})=>[n("span",le,d(E(e.ttc_dh))+" DH",1)]),_:1}),a(r,{field:"statut",header:"Statut",style:{width:"130px"}},{body:l(({data:e})=>[a(M,{value:e.statut,severity:e.statut==="Brouillon"?"secondary":"success"},null,8,["value","severity"])]),_:1}),a(r,{header:"",style:{width:"110px"}},{body:l(({data:e})=>[n("div",re,[C(a(_,{icon:"pi pi-eye",text:"",rounded:"",size:"small",loading:s(B)===e.ndoc,onClick:P=>L(e)},null,8,["loading","onClick"]),[[b,"Apercu"]]),C(a(_,{icon:"pi pi-download",text:"",rounded:"",size:"small",loading:s(N)===e.ndoc,onClick:P=>S(e)},null,8,["loading","onClick"]),[[b,"Telecharger PDF"]])])]),_:1})]),_:1},8,["value","loading"])])}}};export{xe as default};
