import{r as i,f as be,af as xe,g as _e,o as A,c as R,b as s,h as b,B as a,a as l,z as $e,q as ye,j as m,y as Ce,aV as Te,ak as qe,aC as we,ax as De,aW as Se,E as Ae,e as V,ar as J}from"./vendor-0kGcmQpG.js";import{_ as Re,u as Ve,s as o,a as g,S as L,h as O}from"./index-Bn9WoKhP.js";import{_ as N}from"./DataGrid-tb6QVwpZ.js";import{_ as k}from"./ComboDynamique-CzrtYPe1.js";import"./useAgGridConfig-DjXMc6wb.js";const Ne={class:"flex flex-col gap-4"},ke={key:0,class:"flex justify-between items-center mb-2"},Ee={class:"flex items-center gap-4"},Fe={class:"text-sm text-gray-500"},Ie={class:"text-right"},je={class:"text-3xl font-bold text-gray-800"},Ge={class:"text-sm text-gray-500"},Pe={key:1,class:"flex justify-between items-center"},ze={class:"flex gap-2"},Me={class:"flex gap-4 p-4 bg-gray-50 rounded"},Ue={class:"block text-sm font-medium mb-1"},Be={class:"block text-sm font-medium mb-1"},Je={class:"block text-sm font-medium mb-1"},Le={class:"block text-sm font-medium mb-1"},Oe={class:"grid grid-cols-1 md:grid-cols-5 gap-4"},We={class:"p-4 bg-blue-50 rounded-lg border-l-4 border-blue-500"},He={class:"flex items-center"},Ke={class:"text-sm text-gray-600"},Qe={class:"text-2xl font-bold text-blue-600"},Xe={class:"p-4 bg-cyan-50 rounded-lg border-l-4 border-cyan-500"},Ye={class:"flex items-center"},Ze={class:"text-sm text-gray-600"},et={class:"text-2xl font-bold text-cyan-600"},tt={class:"p-4 bg-green-50 rounded-lg border-l-4 border-green-500"},st={class:"flex items-center"},at={class:"text-sm text-gray-600"},lt={class:"text-2xl font-bold text-green-600"},nt={class:"p-4 bg-orange-50 rounded-lg border-l-4 border-orange-500"},rt={class:"flex items-center"},it={class:"text-sm text-gray-600"},ot={class:"text-2xl font-bold text-orange-600"},ut={class:"p-4 bg-purple-50 rounded-lg border-l-4 border-purple-500"},ct={class:"flex items-center"},dt={class:"text-sm text-gray-600"},mt={class:"text-2xl font-bold text-purple-600"},pt={class:"grid grid-cols-1 lg:grid-cols-2 gap-4 mt-4"},vt={class:"flex items-center gap-2"},ft={style:{height:"300px"},class:"mt-2"},ht={class:"flex items-center gap-2"},gt={class:"flex items-center gap-2"},bt={style:{height:"300px"},class:"mt-2"},xt={class:"flex items-center gap-2"},_t={style:{height:"400px"},class:"mt-2"},$t={class:"flex gap-4 p-4 bg-gray-50 rounded mb-4 items-end"},yt={class:"block text-sm font-medium mb-1"},Ct={class:"block text-sm font-medium mb-1"},Tt={class:"ag-theme-quartz",style:{height:"calc(100vh - 320px)",width:"100%"}},qt={__name:"StatistiquesAtelier",props:{modeTV:{type:Boolean,default:!1},refreshInterval:{type:Number,default:3e4}},setup(x){const E=x,{showWarn:W,showError:$}=Ve();let y=null,C=null;const F=i(""),I=i(""),j=()=>{const e=new Date;F.value=e.toLocaleTimeString("fr-FR",{hour:"2-digit",minute:"2-digit",second:"2-digit"}),I.value=e.toLocaleDateString("fr-FR",{weekday:"long",year:"numeric",month:"long",day:"numeric"})},f=i(!1),p=i({}),G=i([]),P=i([]),z=i([]),T=i(0),M=V(()=>T.value===0?"techniciens":"commerciaux"),q=i(o.state.annee_fiscale),H=V(()=>o.state.Annees||[]),w=i(0),D=i([]),K=i(),Q=i(),d=J({dateDebut:null,dateFin:null,technicien:null,site:null}),X=()=>e=>e.value?`<span class="font-medium text-blue-600">${e.value}</span>`:"",Y=()=>e=>e.value?`<div class="flex items-center gap-2">
      <i class="pi pi-cog text-orange-500 text-xs"></i>
      <span>${e.value}</span>
    </div>`:"",Z=()=>e=>e.value?`<div class="flex items-center gap-2">
      <i class="pi pi-building text-blue-500 text-xs"></i>
      <span>${e.value}</span>
    </div>`:"",ee=()=>e=>e.value?`<span class="inline-flex items-center px-2 py-1 rounded text-xs font-medium text-white" style="background-color: ${e.data?.statut_reparation_couleur||"#6c757d"};">${e.value}</span>`:"",te=()=>e=>e.value?`<div class="flex items-center gap-2">
      <i class="pi pi-user text-purple-500 text-xs"></i>
      <span>${e.value}</span>
    </div>`:"",se=()=>e=>{const t=e.value||0;if(t===0)return'<span class="text-gray-400">-</span>';const n=Math.floor(t/60),r=t%60,u=n>0?`${n}h ${r}min`:`${r}min`;return`<span class="font-bold ${n>=2?"text-orange-600":"text-green-600"}">${u}</span>`},ae=()=>e=>{const t=e.value;return t==null?"":t===0?`<span class="text-green-600">Aujourd'hui</span>`:t===1?'<span class="text-gray-600">1 jour</span>':`<span class="${t>7?"text-red-600":"text-gray-600"}">${t} jours</span>`},le=()=>e=>e.value?`<div class="flex items-center gap-2">
      <i class="pi pi-user text-blue-500 text-xs"></i>
      <span class="font-medium">${e.value}</span>
    </div>`:"",S=e=>t=>t.value?`<span class="inline-flex items-center justify-center px-2 py-1 rounded text-xs font-medium text-white" style="background-color: ${e}; min-width: 30px">${t.value}</span>`:"",ne=()=>e=>{if(!e.value)return'<span class="text-gray-400">-</span>';const t=e.value,n=Math.floor(t/60),r=t%60;return`<span class="font-medium text-purple-600">${n>0?`${n}h ${r}min`:`${r}min`}</span>`},re=V(()=>{const e=p.value;if(!e||!e.total_equipements)return{labels:[],datasets:[]};const t=[e.equipements_en_cours||0,e.reparations_en_attente||0,e.reparations_terminees||0,e.reparations_livrees||0],n=t.reduce((u,_)=>u+_,0),r=u=>n>0?Math.round(u/n*100):0;return{labels:[`En cours (${r(t[0])}%)`,`En attente (${r(t[1])}%)`,`Terminées (${r(t[2])}%)`,`Livrées (${r(t[3])}%)`],datasets:[{data:t,backgroundColor:["#0d6efd","#6c757d","#198754","#8b5cf6"]}]}}),ie={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"bottom"},tooltip:{callbacks:{label:e=>{const t=e.dataset.data.reduce((r,u)=>r+u,0),n=t>0?Math.round(e.raw/t*100):0;return` ${e.raw} équipements (${n}%)`}}}}},U=J({lecture:!1});be(async()=>{await oe(),await v(),E.modeTV&&(j(),C=setInterval(j,1e3),y=setInterval(()=>{M.value==="techniciens"?v():h()},E.refreshInterval))}),xe(()=>{y&&clearInterval(y),C&&clearInterval(C)});const oe=async()=>{try{const t=(await g.post(`${o.lienApi}/verifierDroit/${o.state.dbCommun6}`,{id_utilisateur:o.userId,id_page:1004,mail:o.state.userCloud.mail})).data;t&&Object.keys(t).length>0&&(U.lecture=t.lecture),U.lecture||(W("Vous n'avez pas le droit, veuillez consulter l'administrateur"),L("StatistiquesAtelier"))}catch(e){$(`Une erreur s'est produite lors de la vérification des droits. ${e}`)}},v=async()=>{f.value=!0;const e={id_technicien:d.technicien||0,dateDebut:d.dateDebut||null,dateFin:d.dateFin||null,id_site_atelier:d.site||null};try{const[t,n,r,u]=await Promise.all([g.post(`${o.lienApi}/statistiquesGlobales/${o.db}`,e),g.post(`${o.lienApi}/equipementsParTechnicien/${o.db}`,e),g.post(`${o.lienApi}/equipementsParStatutTechnicien/${o.db}`,{id_technicien:e.id_technicien}),g.post(`${o.lienApi}/equipementsEnCours/${o.db}`,{statistiques:!0,enCoursUniquement:!0})]);p.value=t.data||{},G.value=n.data||[],P.value=r.data||[],z.value=u.data||[]}catch(t){$("Erreur lors du chargement des statistiques : "+t.message)}finally{f.value=!1}},ue=e=>{e.index===1&&D.value.length===0&&h()},ce=e=>e.path,de=i({headerName:"Élément",minWidth:250,cellRendererParams:{suppressCount:!0,innerRenderer:e=>e.value},sortable:!0,filter:"agTextColumnFilter"}),me=i([...[{field:"Janvier",headerName:"Janvier"},{field:"Fevrier",headerName:"Février"},{field:"Mars",headerName:"Mars"},{field:"Avril",headerName:"Avril"},{field:"Mai",headerName:"Mai"},{field:"Juin",headerName:"Juin"},{field:"Juillet",headerName:"Juillet"},{field:"Aout",headerName:"Août"},{field:"Septembre",headerName:"Septembre"},{field:"Octobre",headerName:"Octobre"},{field:"Novembre",headerName:"Novembre"},{field:"Decembre",headerName:"Décembre"}].map(e=>({...e,width:100,sortable:!0,filter:"agNumberColumnFilter",cellClass:"ag-right-aligned-cell",valueFormatter:t=>t.value==null||t.value===0?"":O(t.value)})),{field:"Total",headerName:"Total",width:120,sortable:!0,filter:"agNumberColumnFilter",cellClass:"ag-right-aligned-cell",cellStyle:{fontWeight:"bold",backgroundColor:"#e6f7ff"},valueFormatter:e=>e.value==null||e.value===0?"":O(e.value)}]),pe=i({sortable:!0,filter:"agTextColumnFilter",resizable:!0,suppressHeaderMenuButton:!0}),ve=e=>{Q.value=e.api},h=async()=>{f.value=!0;try{const e=await g.post(`${o.lienApi}/statistiquesCommerciaux/${o.db}`,{annee:q.value,IDcommercial:w.value||0});D.value=e.data}catch(e){$("Erreur lors du chargement des statistiques commerciaux : "+e.message)}finally{f.value=!1}};return(e,t)=>{const n=$e,r=Te,u=qe,_=we,B=Ce,fe=De,he=_e("ag-grid-vue"),ge=Se;return A(),R("div",{class:Ae(["col-12 rounded bg-white",x.modeTV?"h-screen p-6":"h-[92vh] p-4"])},[s("div",Ne,[x.modeTV?(A(),R("div",ke,[s("div",Ee,[t[10]||(t[10]=s("h1",{class:"text-2xl font-bold text-gray-800"},"Statistiques Atelier",-1)),s("span",Fe,[t[9]||(t[9]=s("i",{class:"pi pi-refresh mr-1"},null,-1)),b(" Auto-refresh: "+a(x.refreshInterval/1e3)+"s ",1)])]),s("div",Ie,[s("div",je,a(F.value),1),s("div",Ge,a(I.value),1)])])):(A(),R("div",Pe,[s("div",ze,[l(n,{label:e.$tr("Actualiser"),icon:"pi pi-refresh",onClick:t[0]||(t[0]=c=>M.value==="techniciens"?v():h()),loading:f.value},null,8,["label","loading"]),l(n,{icon:"pi pi-times",label:e.$tr("Fermer"),text:"",onClick:t[1]||(t[1]=c=>ye(L)("StatistiquesAtelier"))},null,8,["label"])])])),l(ge,{activeIndex:T.value,"onUpdate:activeIndex":t[8]||(t[8]=c=>T.value=c),onTabChange:ue},{default:m(()=>[l(B,{header:"Statistiques Techniciens"},{default:m(()=>[s("div",Me,[s("div",null,[s("label",Ue,a(e.$tr("Date début")),1),l(r,{size:"small",modelValue:d.dateDebut,"onUpdate:modelValue":t[2]||(t[2]=c=>d.dateDebut=c),dateFormat:"dd/mm/yy",onDateSelect:v,placeholder:e.$tr("Date début")},null,8,["modelValue","placeholder"])]),s("div",null,[s("label",Be,a(e.$tr("Date fin")),1),l(r,{size:"small",modelValue:d.dateFin,"onUpdate:modelValue":t[3]||(t[3]=c=>d.dateFin=c),dateFormat:"dd/mm/yy",onDateSelect:v,placeholder:e.$tr("Date fin")},null,8,["modelValue","placeholder"])]),s("div",null,[s("label",Je,a(e.$tr("Technicien")),1),l(k,{modelValue:d.technicien,"onUpdate:modelValue":[t[4]||(t[4]=c=>d.technicien=c),v],table:"utilisateur_techicien",placeholder:e.$tr("Tous les techniciens")},null,8,["modelValue","placeholder"])]),s("div",null,[s("label",Le,a(e.$tr("Site Atelier")),1),l(k,{modelValue:d.site,"onUpdate:modelValue":[t[5]||(t[5]=c=>d.site=c),v],placeholder:e.$tr("Tous les sites"),table:"site",ajouter:!1},null,8,["modelValue","placeholder"])])]),t[20]||(t[20]=s("div",{class:"h-2"},null,-1)),s("div",Oe,[s("div",We,[s("div",He,[t[11]||(t[11]=s("div",{class:"p-2 bg-blue-100 rounded-lg mr-3"},[s("i",{class:"pi pi-wrench text-blue-600 text-xl"})],-1)),s("div",null,[s("p",Ke,a(e.$tr("Total Équipements")),1),s("p",Qe,a(p.value.total_equipements),1)])])]),s("div",Xe,[s("div",Ye,[t[12]||(t[12]=s("div",{class:"p-2 bg-cyan-100 rounded-lg mr-3"},[s("i",{class:"pi pi-sync text-cyan-600 text-xl"})],-1)),s("div",null,[s("p",Ze,a(e.$tr("En Cours")),1),s("p",et,a(p.value.equipements_en_cours),1)])])]),s("div",tt,[s("div",st,[t[13]||(t[13]=s("div",{class:"p-2 bg-green-100 rounded-lg mr-3"},[s("i",{class:"pi pi-cog text-green-600 text-xl"})],-1)),s("div",null,[s("p",at,a(e.$tr("Total Réparations")),1),s("p",lt,a(p.value.total_reparations),1)])])]),s("div",nt,[s("div",rt,[t[14]||(t[14]=s("div",{class:"p-2 bg-orange-100 rounded-lg mr-3"},[s("i",{class:"pi pi-clock text-orange-600 text-xl"})],-1)),s("div",null,[s("p",it,a(e.$tr("Total Interventions")),1),s("p",ot,a(p.value.total_interventions),1)])])]),s("div",ut,[s("div",ct,[t[15]||(t[15]=s("div",{class:"p-2 bg-purple-100 rounded-lg mr-3"},[s("i",{class:"pi pi-hourglass text-purple-600 text-xl"})],-1)),s("div",null,[s("p",dt,a(e.$tr("En Attente")),1),s("p",mt,a(p.value.reparations_en_attente),1)])])])]),s("div",pt,[l(u,null,{title:m(()=>[s("div",vt,[t[16]||(t[16]=s("i",{class:"pi pi-users text-blue-600"},null,-1)),b(" "+a(e.$tr("Réparations par Technicien")),1)])]),content:m(()=>[s("div",ft,[l(N,{"excel-file-name":"Statistiques atelier","excel-sheet-name":"Statistiques atelier","row-data":G.value,"excluded-columns":["En attente","temps_passe","nb_equipements"],"column-widths":{Technicien:180,Réparés:100,"En cours":100,Retour:100,"Temps moyen":120},"custom-renderers":{Technicien:le(),Réparés:S("#198754"),"En cours":S("#0d6efd"),Retour:S("#dc3545"),"Temps moyen":ne()},"enable-totals":!0,"numeric-columns":["Réparés","En cours","Retour"],"show-checkbox":!1,"enable-filter":!1,"auto-size-columns":!0},null,8,["row-data","custom-renderers"])])]),_:1}),l(u,null,{title:m(()=>[s("div",ht,[t[17]||(t[17]=s("i",{class:"pi pi-chart-bar text-orange-600"},null,-1)),b(" "+a(e.$tr("Réparations par Statut")),1)])]),content:m(()=>[l(_,{type:"doughnut",data:re.value,options:ie,class:"w-full h-75"},null,8,["data"])]),_:1})]),l(u,{class:"mt-4"},{title:m(()=>[s("div",gt,[t[18]||(t[18]=s("i",{class:"pi pi-th-large text-teal-600"},null,-1)),b(" "+a(e.$tr("Équipements par Statut et Technicien")),1)])]),content:m(()=>[s("div",bt,[l(N,{"excel-file-name":"Statistiques atelier","excel-sheet-name":"Statistiques atelier","row-data":P.value,"show-checkbox":!1,"enable-filter":!1,"auto-size-columns":!0},null,8,["row-data"])])]),_:1}),l(u,{class:"mt-4"},{title:m(()=>[s("div",xt,[t[19]||(t[19]=s("i",{class:"pi pi-list text-indigo-600"},null,-1)),b(" "+a(e.$tr("Équipements en-cours")),1)])]),content:m(()=>[s("div",_t,[l(N,{"excel-file-name":"Statistiques atelier","excel-sheet-name":"Statistiques atelier","row-data":z.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc","statut_reparation_couleur"],"column-widths":{ndoc:80,Equipement:320,client_nom:300,statut_reparation:180,technicien:130,date_depot:120,temps_total_minutes:150,jours_ecoules:120},"date-only":["date_depot"],"custom-renderers":{ndoc:X(),Equipement:Y(),client_nom:Z(),statut_reparation:ee(),technicien:te(),temps_total_minutes:se(),jours_ecoules:ae()},"column-names":{ndoc:"N°",Equipement:"Équipement",client_nom:"Client",statut_reparation:"Statut",technicien:"Technicien",date_depot:"Date dépôt",temps_total_minutes:"Temps passé",jours_ecoules:"Écoulé"},"enable-totals":!0,"numeric-columns":["temps_total_minutes"]},null,8,["row-data","custom-renderers"])])]),_:1})]),_:1}),l(B,{header:"Performance Commerciaux"},{default:m(()=>[s("div",$t,[s("div",null,[s("label",yt,a(e.$tr("Année")),1),l(fe,{modelValue:q.value,"onUpdate:modelValue":t[6]||(t[6]=c=>q.value=c),options:H.value,optionLabel:"Annee",optionValue:"Annee",placeholder:"Année",class:"w-48",onChange:h},null,8,["modelValue","options"])]),s("div",null,[s("label",Ct,a(e.$tr("Commercial")),1),l(k,{modelValue:w.value,"onUpdate:modelValue":t[7]||(t[7]=c=>w.value=c),table:"commercial",placeholder:e.$tr("Tous les commerciaux"),showClear:"",class:"w-56",onChange:h},null,8,["modelValue","placeholder"])]),l(n,{label:e.$tr("Actualiser"),icon:"pi pi-refresh",onClick:h,loading:f.value},null,8,["label","loading"])]),t[21]||(t[21]=s("div",{class:"h-2"},null,-1)),s("div",Tt,[l(he,{ref_key:"agGridCommerciaux",ref:K,localeText:e.$agGridLocale,rowData:D.value,columnDefs:me.value,defaultColDef:pe.value,theme:e.$agGridTheme,treeData:!0,getDataPath:ce,autoGroupColumnDef:de.value,groupDefaultExpanded:0,animateRows:!0,onGridReady:ve,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},null,8,["localeText","rowData","columnDefs","defaultColDef","theme","autoGroupColumnDef"])])]),_:1})]),_:1},8,["activeIndex"])])],2)}}},Nt=Re(qt,[["__scopeId","data-v-2f4beb72"]]);export{Nt as default};
