import{O as B,g as D,S as I,y as z,A,z as M}from"./primevue-CfIk0_DY.js";import{b as T,s as g}from"./index-BxIwIJfy.js";import{o as F,b as i,c as d,d as s,f as h,t as l,p as v,v as a,l as n,k,y as m,a as x}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";const L={class:"max-w-5xl mx-auto"},O={class:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",style:{"margin-bottom":"20px"}},R={class:"text-gray-500",style:{"margin-top":"2px"}},U={key:0},j={class:"flex items-center gap-2"},E={key:0,class:"text-center text-gray-400",style:{padding:"48px 0"}},q={key:1,class:"bg-white rounded-xl shadow-sm text-center",style:{padding:"48px 24px"}},G={class:"font-mono text-gray-600"},H={class:"font-medium text-gray-800"},J={key:0,class:"text-gray-400"},K={class:"font-mono text-gray-600"},Q={class:"font-mono text-gray-600"},le={__name:"PortailClientPersonnel",setup(W){const w=m(()=>g.state.portailClientDb),C=m(()=>g.state.portailClientToken),c=x([]),f=x(!1),y=x(""),p=x(null),u=m(()=>[...new Set(c.value.map(o=>o.site).filter(Boolean))].sort()),b=m(()=>{const o=y.value.trim().toLowerCase();return c.value.filter(e=>p.value&&e.site!==p.value?!1:o?[e.Nom,e.Prenom,e.Matricule,e.cin].filter(Boolean).some(_=>String(_).toLowerCase().includes(o)):!0)}),N=o=>{if(!o)return"—";const e=new Date(o);return isNaN(e)?"—":e.toLocaleDateString("fr-FR")};return F(async()=>{if(w.value){f.value=!0;try{const o=await T.get(`${g.lienApi}/portail-client/personnel/${w.value}`,{headers:{Authorization:`Bearer ${C.value}`}});c.value=o.data||[]}catch{c.value=[]}finally{f.value=!1}}}),(o,e)=>{const _=B,V=D,S=I,P=z,r=A,$=M;return i(),d("div",L,[s("div",O,[s("div",null,[e[2]||(e[2]=s("h1",{class:"text-2xl font-bold text-gray-800"},"Personnel affecté",-1)),s("p",R,[h(l(b.value.length)+" agent(s) en poste",1),u.value.length>1?(i(),d("span",U," · "+l(u.value.length)+" sites",1)):v("",!0)])]),s("div",j,[a(S,{iconPosition:"left",style:{"max-width":"240px"}},{default:n(()=>[a(_,{class:"pi pi-search"}),a(V,{modelValue:y.value,"onUpdate:modelValue":e[0]||(e[0]=t=>y.value=t),placeholder:"Nom, matricule, CIN",size:"small",class:"w-full"},null,8,["modelValue"])]),_:1}),u.value.length>1?(i(),k(P,{key:0,modelValue:p.value,"onUpdate:modelValue":e[1]||(e[1]=t=>p.value=t),options:u.value,size:"small",showClear:"",placeholder:"Tous les sites",style:{"min-width":"170px"}},null,8,["modelValue","options"])):v("",!0)])]),f.value?(i(),d("div",E,[...e[3]||(e[3]=[s("i",{class:"pi pi-spin pi-spinner text-2xl"},null,-1)])])):c.value.length?(i(),k($,{key:2,value:b.value,stripedRows:"",size:"small",paginator:"",rows:25,rowsPerPageOptions:[25,50,100],class:"bg-white rounded-xl shadow-sm overflow-hidden"},{empty:n(()=>[...e[5]||(e[5]=[s("div",{class:"text-center text-gray-400",style:{padding:"32px 0"}},"Aucun résultat.",-1)])]),default:n(()=>[a(r,{field:"Matricule",header:"Matricule",style:{width:"120px"}},{body:n(({data:t})=>[s("span",G,l(t.Matricule),1)]),_:1}),a(r,{header:"Agent"},{body:n(({data:t})=>[s("div",H,l(t.Nom)+" "+l(t.Prenom),1),t.poste?(i(),d("div",J,l(t.poste),1)):v("",!0)]),_:1}),a(r,{field:"cin",header:"CIN",style:{width:"120px"}},{body:n(({data:t})=>[s("span",K,l(t.cin||"—"),1)]),_:1}),a(r,{field:"cnss",header:"CNSS",style:{width:"130px"}},{body:n(({data:t})=>[s("span",Q,l(t.cnss||"—"),1)]),_:1}),a(r,{field:"site",header:"Site",style:{width:"180px"}},{body:n(({data:t})=>[h(l(t.site||"—"),1)]),_:1}),a(r,{field:"date_entree",header:"Depuis",style:{width:"120px"}},{body:n(({data:t})=>[h(l(N(t.date_entree)),1)]),_:1})]),_:1},8,["value"])):(i(),d("div",q,[...e[4]||(e[4]=[s("i",{class:"pi pi-id-card text-gray-300",style:{"font-size":"40px"}},null,-1),s("p",{class:"text-gray-500",style:{"margin-top":"12px"}},"Aucun agent affecté actuellement.",-1)])]))])}}};export{le as default};
