import{y as L}from"./primevue-CfIk0_DY.js";import{b as y,s as u}from"./index-BxIwIJfy.js";import{a as n,o as M,b as r,c as i,d as a,t as d,v as P,f as h,F as w,C as R,G as I,q as N,y as f}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";const T={class:"max-w-5xl mx-auto"},Y={class:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",style:{"margin-bottom":"20px"}},$={class:"text-gray-500",style:{"margin-top":"2px"}},E={key:0,class:"text-center text-gray-400",style:{padding:"48px 0"}},H={key:1,class:"bg-white rounded-xl shadow-sm text-center text-gray-500",style:{padding:"40px 16px"}},j={key:2,class:"bg-white rounded-xl shadow-sm text-center text-gray-500",style:{padding:"40px 16px"}},G={class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4"},q={class:"flex-1 min-w-0"},O={class:"text-gray-500",style:{"font-size":"13px"}},U={class:"text-gray-400",style:{"margin-top":"16px"}},te={__name:"PortailCabinetIndicateurs",setup(J){const g={teal:{bg:"#ccfbf1",fg:"#0f766e"},amber:{bg:"#fef3c7",fg:"#b45309"},red:{bg:"#fee2e2",fg:"#b91c1c"},indigo:{bg:"#e0e7ff",fg:"#4338ca"},blue:{bg:"var(--omag-100)",fg:"var(--omag-600)"},slate:{bg:"#f1f5f9",fg:"#475569"}},k={ca_ht:"chiffre_affaires",total_charges:"total_charges",resultat:"resultat_courant",marge_brute:"marge_brute",masse_salariale:"masse_salariale",tresorerie:"tresorerie",creances_clients:"creances_clients",dettes_frs:"dettes_frs",tva_decaisser:"tva_decaisser",stock_valorise:"stock_valorise",comptes_attente:"nb_comptes_attente",derniere_ecriture:"derniere_ecriture",ecritures_mois:"nb_ecritures_mois"},x=f(()=>u.state.portailCabinetToken),D=f(()=>u.state.portailCabinetSociete?.Nom||""),o=n(new Date().getFullYear()),F=n([new Date().getFullYear(),new Date().getFullYear()-1,new Date().getFullYear()-2]),b=n([]),l=n({}),c=n(!1),m=n(!1),_=f(()=>b.value),A=e=>e==null||isNaN(Number(e))?"0,00 DH":Number(e).toLocaleString("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2})+" DH",S=e=>e==null||isNaN(Number(e))?"0":Number(e).toLocaleString("fr-FR"),V=e=>{if(!e)return"—";const t=new Date(e);return isNaN(t)?"—":t.toLocaleDateString("fr-FR")},p=e=>l.value[k[e.code]],C=e=>{const t=p(e);return e.format==="date"?V(t):e.format==="nombre"?S(t):A(t)},z=e=>e.code==="resultat"?Number(p(e))>=0?"text-green-600":"text-red-600":e.code==="comptes_attente"&&Number(p(e))>0?"text-amber-600":"text-gray-800",v=async()=>{m.value=!0,c.value=!1;try{const[e,t]=await Promise.all([y.get(`${u.lienApi}/portail-cabinet/indicateurs-config`,{headers:{Authorization:`Bearer ${x.value}`}}),y.get(`${u.lienApi}/portail-cabinet/indicateurs`,{params:{annee:o.value},headers:{Authorization:`Bearer ${x.value}`}})]);b.value=e.data||[],t.data?.indisponible?(c.value=!0,l.value={}):l.value=t.data||{}}catch{c.value=!0,l.value={}}finally{m.value=!1}};return M(v),(e,t)=>{const B=L;return r(),i("div",T,[a("div",Y,[a("div",null,[t[1]||(t[1]=a("h1",{class:"text-2xl font-bold text-gray-800"},"Mes indicateurs",-1)),a("p",$,"Synthèse comptable de "+d(D.value),1)]),P(B,{modelValue:o.value,"onUpdate:modelValue":t[0]||(t[0]=s=>o.value=s),options:F.value,onChange:v,size:"small",style:{"min-width":"100px"}},null,8,["modelValue","options"])]),m.value?(r(),i("div",E,[...t[2]||(t[2]=[a("i",{class:"pi pi-spin pi-spinner text-3xl"},null,-1)])])):c.value?(r(),i("div",H,[...t[3]||(t[3]=[a("i",{class:"pi pi-info-circle text-3xl block",style:{"margin-bottom":"12px"}},null,-1),h(" Indicateurs non disponibles pour cette société. ",-1),a("div",{class:"text-gray-400",style:{"margin-top":"6px"}},"La comptabilité n'est peut-être pas encore tenue dans OMAG pour cet exercice.",-1)])])):_.value.length===0?(r(),i("div",j,[...t[4]||(t[4]=[a("i",{class:"pi pi-info-circle text-3xl block",style:{"margin-bottom":"12px"}},null,-1),h(" Aucun indicateur n'est activé pour le moment. ",-1),a("div",{class:"text-gray-400",style:{"margin-top":"6px"}},"Votre cabinet comptable peut activer des indicateurs depuis sa configuration.",-1)])])):(r(),i(w,{key:3},[a("div",G,[(r(!0),i(w,null,R(_.value,s=>(r(),i("div",{key:s.code,class:"bg-white rounded-xl shadow-sm flex items-center gap-3",style:{padding:"16px"}},[a("div",{class:"flex items-center justify-center rounded-lg",style:I({width:"44px",height:"44px",background:g[s.couleur]?.bg||"#f3f4f6",color:g[s.couleur]?.fg||"#9ca3af"})},[a("i",{class:N([s.icone,"text-xl"])},null,2)],4),a("div",q,[a("div",O,d(s.libelle),1),a("div",{class:N(["text-2xl font-bold",z(s)]),style:{"margin-top":"2px"}},d(C(s)),3)])]))),128))]),a("p",U," Indicateurs fournis par votre cabinet comptable, calculés sur l'exercice "+d(o.value)+". ",1)],64))])}}};export{te as default};
