import{y as j,A as L,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 d,o as X,b as D,c as Z,a7 as n,k as ee,p as te,d as a,t as u,v as s,l,f as b,j as C,y as h}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"},se={class:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",style:{"margin-bottom":"16px"}},ae={class:"text-gray-500",style:{"margin-top":"2px"}},ne={class:"font-mono font-bold text-blue-700"},le={class:"font-semibold"},ie={class:"flex gap-1"},xe={__name:"PortailClientDevis",setup(re){const{showError:f}=K(),{ouvrireReport:p,urlFichierRapport:F,nomFichierImpression:$,dataReport:k,apercuEnCours:N,telechargementEnCours:R,apercevoir:T,telecharger:V}=W(),g=h(()=>c.state.portailClientDb),y=h(()=>c.state.portailClientClient?.code_client),B=h(()=>c.state.portailClientToken),m=d(new Date().getFullYear()),z=d([new Date().getFullYear(),new Date().getFullYear()-1,new Date().getFullYear()-2]),r=d([]),v=d(!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(!(!g.value||!y.value)){v.value=!0;try{const t=await O.get(`${c.lienApi}/portail-client/devis/${g.value}/${encodeURIComponent(y.value)}`,{params:{annee:m.value},headers:{Authorization:`Bearer ${B.value}`}});r.value=t.data||[]}catch{r.value=[]}finally{v.value=!1}}},S=async t=>{try{await T({type:"devis",nDoc:t.ndoc,libelleDocument:"Devis",fileName:`Devis_${t.ndoc}`})}catch(o){f(o.message||"Erreur lors de l'apercu.")}},I=async t=>{try{await V({type:"devis",nDoc:t.ndoc,libelleDocument:"Devis",fileName:`Devis_${t.ndoc}.pdf`})}catch(o){f(o.message||"Erreur lors du telechargement.")}};return X(x),(t,o)=>{const M=j,i=L,Y=H,_=q,P=J,w=G;return D(),Z("div",oe,[n(p)?(D(),ee(Q,{key:0,show:n(p),onClose:o[0]||(o[0]=e=>p.value=!1),data:n(k),urlFichier:n(F),nomFichier:n($)},null,8,["show","data","urlFichier","nomFichier"])):te("",!0),a("div",se,[a("div",null,[o[2]||(o[2]=a("h1",{class:"text-2xl font-bold text-gray-800"},"Mes devis",-1)),a("p",ae,u(r.value.length)+" resultat(s)",1)]),s(M,{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"])]),s(P,{value:r.value,loading:v.value,stripedRows:"",size:"small",paginator:"",rows:20,class:"bg-white rounded-xl shadow-sm overflow-hidden"},{empty:l(()=>[...o[3]||(o[3]=[a("div",{class:"text-center text-gray-400",style:{padding:"32px 0"}},[a("i",{class:"pi pi-inbox text-3xl block",style:{"margin-bottom":"8px"}}),b(" Aucun devis pour cette annee. ")],-1)])]),default:l(()=>[s(i,{field:"ndoc",header:"N°",style:{width:"110px"}},{body:l(({data:e})=>[a("span",ne,u(e.ndoc),1)]),_:1}),s(i,{field:"date",header:"Date",style:{width:"120px"}},{body:l(({data:e})=>[b(u(A(e.date)),1)]),_:1}),s(i,{field:"ttc_dh",header:"Montant TTC",style:{width:"150px"}},{body:l(({data:e})=>[a("span",le,u(E(e.ttc_dh))+" DH",1)]),_:1}),s(i,{field:"statut",header:"Statut",style:{width:"130px"}},{body:l(({data:e})=>[s(Y,{value:e.statut,severity:e.statut==="Brouillon"?"secondary":"success"},null,8,["value","severity"])]),_:1}),s(i,{header:"",style:{width:"110px"}},{body:l(({data:e})=>[a("div",ie,[C(s(_,{icon:"pi pi-eye",text:"",rounded:"",size:"small",loading:n(N)===e.ndoc,onClick:U=>S(e)},null,8,["loading","onClick"]),[[w,"Apercu"]]),C(s(_,{icon:"pi pi-download",text:"",rounded:"",size:"small",loading:n(R)===e.ndoc,onClick:U=>I(e)},null,8,["loading","onClick"]),[[w,"Telecharger PDF"]])])]),_:1})]),_:1},8,["value","loading"])])}}};export{xe as default};
