import{y as F,A as N,z as R}from"./primevue-CfIk0_DY.js";import{b as V,s as d}from"./index-BxIwIJfy.js";import{a as c,o as $,b as k,c as M,d as n,f as m,t as l,v as o,l as i,y as u}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";const z={class:"max-w-5xl mx-auto"},A={class:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",style:{"margin-bottom":"16px"}},B={class:"text-gray-500",style:{"margin-top":"2px"}},S={class:"font-semibold text-green-600"},T={class:"font-mono font-bold text-blue-700"},Y={class:"font-semibold text-green-600"},q={__name:"PortailClientReglements",setup(E){const g=u(()=>d.state.portailClientDb),x=u(()=>d.state.portailClientClient?.code_client),v=u(()=>d.state.portailClientToken),p=c(new Date().getFullYear()),b=c([new Date().getFullYear(),new Date().getFullYear()-1,new Date().getFullYear()-2]),r=c([]),f=c(!1),w=u(()=>r.value.reduce((e,t)=>e+Number(t.montant||0),0)),_=e=>e==null?"0,00":Number(e).toLocaleString("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2}),h=e=>{if(!e)return"—";const t=new Date(e);return isNaN(t)?"—":t.toLocaleDateString("fr-FR")},y=async()=>{if(!(!g.value||!x.value)){f.value=!0;try{const e=await V.get(`${d.lienApi}/portail-client/reglements/${g.value}/${encodeURIComponent(x.value)}`,{params:{annee:p.value},headers:{Authorization:`Bearer ${v.value}`}});r.value=e.data||[]}catch{r.value=[]}finally{f.value=!1}}};return $(y),(e,t)=>{const D=F,s=N,C=R;return k(),M("div",z,[n("div",A,[n("div",null,[t[1]||(t[1]=n("h1",{class:"text-2xl font-bold text-gray-800"},"Mes reglements",-1)),n("p",B,[m(l(r.value.length)+" resultat(s) · Total : ",1),n("span",S,l(_(w.value))+" DH",1)])]),o(D,{modelValue:p.value,"onUpdate:modelValue":t[0]||(t[0]=a=>p.value=a),options:b.value,onChange:y,size:"small",style:{"min-width":"100px"}},null,8,["modelValue","options"])]),o(C,{value:r.value,loading:f.value,stripedRows:"",size:"small",paginator:"",rows:20,class:"bg-white rounded-xl shadow-sm overflow-hidden"},{empty:i(()=>[...t[2]||(t[2]=[n("div",{class:"text-center text-gray-400",style:{padding:"32px 0"}},[n("i",{class:"pi pi-wallet text-3xl block",style:{"margin-bottom":"8px"}}),m(" Aucun reglement pour cette annee. ")],-1)])]),default:i(()=>[o(s,{field:"ndoc",header:"N°",style:{width:"110px"}},{body:i(({data:a})=>[n("span",T,l(a.ndoc),1)]),_:1}),o(s,{field:"date",header:"Date",style:{width:"120px"}},{body:i(({data:a})=>[m(l(h(a.date)),1)]),_:1}),o(s,{field:"mode_paiement",header:"Mode",style:{width:"140px"}}),o(s,{field:"ref_paiement",header:"Reference"}),o(s,{field:"date_ech",header:"Echeance",style:{width:"120px"}},{body:i(({data:a})=>[m(l(h(a.date_ech)),1)]),_:1}),o(s,{field:"montant",header:"Montant",style:{width:"140px"}},{body:i(({data:a})=>[n("span",Y,l(_(a.montant))+" DH",1)]),_:1})]),_:1},8,["value","loading"])])}}};export{q as default};
