import{b as $e,D as ye,E as Ce,F as Te,G as qe,V as we,W as De,X as Se,y as Ae,N as Re}from"./primevue-CfIk0_DY.js";import{u as Ne,s as i,b as g,S as L,o as O}from"./index-BxIwIJfy.js";import{D as R}from"./DataGrid-CoMfrBJA.js";import{C as N}from"./ComboDynamique-BzWI4ISP.js";import{a as o,o as Ve,P as ke,h as Ee,b as V,c as k,d as s,f as x,t as a,v as l,a7 as Fe,l as c,q as Ge,y as E,E as W}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";import"./useAgGridConfig-Dp3DkgaV.js";const Pe={class:"flex flex-col gap-4"},je={key:0,class:"flex justify-between items-center mb-2"},Ie={class:"flex items-center gap-4"},Me={class:"text-sm text-gray-500"},ze={class:"text-right"},Ue={class:"text-3xl font-bold text-gray-800"},Be={class:"text-sm text-gray-500"},Je={key:1,class:"flex justify-between items-center"},Le={class:"flex gap-2"},Oe={class:"flex gap-4 p-4 bg-gray-50 rounded"},We={class:"block text-sm font-medium mb-1"},He={class:"block text-sm font-medium mb-1"},Xe={class:"block text-sm font-medium mb-1"},Ke={class:"block text-sm font-medium mb-1"},Qe={class:"grid grid-cols-1 md:grid-cols-5 gap-4"},Ye={class:"p-4 bg-blue-50 rounded-lg border-l-4 border-blue-500"},Ze={class:"flex items-center"},et={class:"text-sm text-gray-600"},tt={class:"text-2xl font-bold text-blue-600"},st={class:"p-4 bg-cyan-50 rounded-lg border-l-4 border-cyan-500"},lt={class:"flex items-center"},at={class:"text-sm text-gray-600"},nt={class:"text-2xl font-bold text-cyan-600"},rt={class:"p-4 bg-green-50 rounded-lg border-l-4 border-green-500"},it={class:"flex items-center"},ot={class:"text-sm text-gray-600"},ut={class:"text-2xl font-bold text-green-600"},ct={class:"p-4 bg-orange-50 rounded-lg border-l-4 border-orange-500"},dt={class:"flex items-center"},mt={class:"text-sm text-gray-600"},pt={class:"text-2xl font-bold text-orange-600"},vt={class:"p-4 bg-purple-50 rounded-lg border-l-4 border-purple-500"},ft={class:"flex items-center"},ht={class:"text-sm text-gray-600"},gt={class:"text-2xl font-bold text-purple-600"},bt={class:"grid grid-cols-1 lg:grid-cols-2 gap-4 mt-4"},xt={class:"flex items-center gap-2"},_t={style:{height:"300px"},class:"mt-2"},$t={class:"flex items-center gap-2"},yt={class:"flex items-center gap-2"},Ct={style:{height:"300px"},class:"mt-2"},Tt={class:"flex items-center gap-2"},qt={style:{height:"400px"},class:"mt-2"},wt={class:"flex gap-4 p-4 bg-gray-50 rounded mb-4 items-end"},Dt={class:"block text-sm font-medium mb-1"},St={class:"block text-sm font-medium mb-1"},At={class:"ag-theme-quartz",style:{height:"calc(100vh - 320px)",width:"100%"}},Mt={__name:"StatistiquesAtelier",props:{modeTV:{type:Boolean,default:!1},refreshInterval:{type:Number,default:3e4}},setup(_){const F=_,{showWarn:H,showError:y}=Ne();let C=null,T=null;const G=o(""),P=o(""),j=()=>{const e=new Date;G.value=e.toLocaleTimeString("fr-FR",{hour:"2-digit",minute:"2-digit",second:"2-digit"}),P.value=e.toLocaleDateString("fr-FR",{weekday:"long",year:"numeric",month:"long",day:"numeric"})},f=o(!1),p=o({}),I=o([]),M=o([]),z=o([]),q=o("0"),U=E(()=>q.value==="0"?"techniciens":"commerciaux"),w=o(i.state.annee_fiscale),X=E(()=>i.state.Annees||[]),D=o(0),S=o([]),K=o(),Q=o(),d=W({dateDebut:null,dateFin:null,technicien:null,site:null}),Y=()=>e=>e.value?`<span class="font-medium text-blue-600">${e.value}</span>`:"",Z=()=>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>`:"",ee=()=>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>`:"",te=()=>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>`:"",se=()=>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>`:"",le=()=>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,m=n>0?`${n}h ${r}min`:`${r}min`;return`<span class="font-bold ${n>=2?"text-orange-600":"text-green-600"}">${m}</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>`},ne=()=>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>`:"",A=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>`:"",re=()=>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>`},ie=E(()=>{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((m,b)=>m+b,0),r=m=>n>0?Math.round(m/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"]}]}}),oe={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"bottom"},tooltip:{callbacks:{label:e=>{const t=e.dataset.data.reduce((r,m)=>r+m,0),n=t>0?Math.round(e.raw/t*100):0;return` ${e.raw} équipements (${n}%)`}}}}},B=W({lecture:!1});Ve(async()=>{await ue(),await v(),F.modeTV&&(j(),T=setInterval(j,1e3),C=setInterval(()=>{U.value==="techniciens"?v():h()},F.refreshInterval))}),ke(()=>{C&&clearInterval(C),T&&clearInterval(T)});const ue=async()=>{try{const t=(await g.post(`${i.lienApi}/verifierDroit/${i.state.dbCommun6}`,{id_utilisateur:i.userId,id_page:1004,mail:i.state.userCloud.mail})).data;t&&Object.keys(t).length>0&&(B.lecture=t.lecture),B.lecture||(H("Vous n'avez pas le droit, veuillez consulter l'administrateur"),L("StatistiquesAtelier"))}catch(e){y(`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,m]=await Promise.all([g.post(`${i.lienApi}/statistiquesGlobales/${i.db}`,e),g.post(`${i.lienApi}/equipementsParTechnicien/${i.db}`,e),g.post(`${i.lienApi}/equipementsParStatutTechnicien/${i.db}`,{id_technicien:e.id_technicien}),g.post(`${i.lienApi}/equipementsEnCours/${i.db}`,{statistiques:!0,enCoursUniquement:!0})]);p.value=t.data||{},I.value=n.data||[],M.value=r.data||[],z.value=m.data||[]}catch(t){y("Erreur lors du chargement des statistiques : "+t.message)}finally{f.value=!1}},ce=e=>{e.index===1&&S.value.length===0&&h()},de=e=>e.path,me=o({headerName:"Élément",minWidth:250,cellRendererParams:{suppressCount:!0,innerRenderer:e=>e.value},sortable:!0,filter:"agTextColumnFilter"}),pe=o([...[{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)}]),ve=o({sortable:!0,filter:"agTextColumnFilter",resizable:!0,suppressHeaderMenuButton:!0}),fe=e=>{Q.value=e.api},h=async()=>{f.value=!0;try{const e=await g.post(`${i.lienApi}/statistiquesCommerciaux/${i.db}`,{annee:w.value,IDcommercial:D.value||0});S.value=e.data}catch(e){y("Erreur lors du chargement des statistiques commerciaux : "+e.message)}finally{f.value=!1}};return(e,t)=>{const n=$e,r=Ce,m=ye,b=we,$=De,he=Se,J=qe,ge=Ae,be=Ee("ag-grid-vue"),xe=Te,_e=Re;return V(),k("div",{class:Ge(["col-12 rounded bg-white",_.modeTV?"h-screen p-6":"h-[92vh] p-4"])},[s("div",Pe,[_.modeTV?(V(),k("div",je,[s("div",Ie,[t[10]||(t[10]=s("h1",{class:"text-2xl font-bold text-gray-800"},"Statistiques Atelier",-1)),s("span",Me,[t[9]||(t[9]=s("i",{class:"pi pi-refresh mr-1"},null,-1)),x(" Auto-refresh: "+a(_.refreshInterval/1e3)+"s ",1)])]),s("div",ze,[s("div",Ue,a(G.value),1),s("div",Be,a(P.value),1)])])):(V(),k("div",Je,[s("div",Le,[l(n,{label:e.$tr("Actualiser"),icon:"pi pi-refresh",onClick:t[0]||(t[0]=u=>U.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]=u=>Fe(L)("StatistiquesAtelier"))},null,8,["label"])])])),l(_e,{class:"options-tabs",value:q.value,"onUpdate:value":t[8]||(t[8]=u=>q.value=u),onTabChange:ce},{default:c(()=>[l(m,null,{default:c(()=>[l(r,{value:"0"},{default:c(()=>[...t[11]||(t[11]=[s("span",{class:"tab-content"},[s("i",{class:"pi pi-chart-bar"}),s("span",null,"Statistiques Techniciens")],-1)])]),_:1}),l(r,{value:"1"},{default:c(()=>[...t[12]||(t[12]=[s("span",{class:"tab-content"},[s("i",{class:"pi pi-chart-line"}),s("span",null,"Performance Commerciaux")],-1)])]),_:1})]),_:1}),l(xe,null,{default:c(()=>[l(J,{value:"0"},{default:c(()=>[s("div",Oe,[s("div",null,[s("label",We,a(e.$tr("Date début")),1),l(b,{size:"small",modelValue:d.dateDebut,"onUpdate:modelValue":t[2]||(t[2]=u=>d.dateDebut=u),dateFormat:"dd/mm/yy",onDateSelect:v,placeholder:e.$tr("Date début")},null,8,["modelValue","placeholder"])]),s("div",null,[s("label",He,a(e.$tr("Date fin")),1),l(b,{size:"small",modelValue:d.dateFin,"onUpdate:modelValue":t[3]||(t[3]=u=>d.dateFin=u),dateFormat:"dd/mm/yy",onDateSelect:v,placeholder:e.$tr("Date fin")},null,8,["modelValue","placeholder"])]),s("div",null,[s("label",Xe,a(e.$tr("Technicien")),1),l(N,{modelValue:d.technicien,"onUpdate:modelValue":[t[4]||(t[4]=u=>d.technicien=u),v],table:"utilisateur_techicien",placeholder:e.$tr("Tous les techniciens")},null,8,["modelValue","placeholder"])]),s("div",null,[s("label",Ke,a(e.$tr("Site Atelier")),1),l(N,{modelValue:d.site,"onUpdate:modelValue":[t[5]||(t[5]=u=>d.site=u),v],placeholder:e.$tr("Tous les sites"),table:"site",ajouter:!1},null,8,["modelValue","placeholder"])])]),t[22]||(t[22]=s("div",{class:"h-2"},null,-1)),s("div",Qe,[s("div",Ye,[s("div",Ze,[t[13]||(t[13]=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",et,a(e.$tr("Total Équipements")),1),s("p",tt,a(p.value.total_equipements),1)])])]),s("div",st,[s("div",lt,[t[14]||(t[14]=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",at,a(e.$tr("En Cours")),1),s("p",nt,a(p.value.equipements_en_cours),1)])])]),s("div",rt,[s("div",it,[t[15]||(t[15]=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",ot,a(e.$tr("Total Réparations")),1),s("p",ut,a(p.value.total_reparations),1)])])]),s("div",ct,[s("div",dt,[t[16]||(t[16]=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",mt,a(e.$tr("Total Interventions")),1),s("p",pt,a(p.value.total_interventions),1)])])]),s("div",vt,[s("div",ft,[t[17]||(t[17]=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",ht,a(e.$tr("En Attente")),1),s("p",gt,a(p.value.reparations_en_attente),1)])])])]),s("div",bt,[l($,null,{title:c(()=>[s("div",xt,[t[18]||(t[18]=s("i",{class:"pi pi-users text-blue-600"},null,-1)),x(" "+a(e.$tr("Réparations par Technicien")),1)])]),content:c(()=>[s("div",_t,[l(R,{"excel-file-name":"Statistiques atelier","excel-sheet-name":"Statistiques atelier","row-data":I.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:ne(),Réparés:A("#198754"),"En cours":A("#0d6efd"),Retour:A("#dc3545"),"Temps moyen":re()},"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($,null,{title:c(()=>[s("div",$t,[t[19]||(t[19]=s("i",{class:"pi pi-chart-bar text-orange-600"},null,-1)),x(" "+a(e.$tr("Réparations par Statut")),1)])]),content:c(()=>[l(he,{type:"doughnut",data:ie.value,options:oe,class:"w-full h-75"},null,8,["data"])]),_:1})]),l($,{class:"mt-4"},{title:c(()=>[s("div",yt,[t[20]||(t[20]=s("i",{class:"pi pi-th-large text-teal-600"},null,-1)),x(" "+a(e.$tr("Équipements par Statut et Technicien")),1)])]),content:c(()=>[s("div",Ct,[l(R,{"excel-file-name":"Statistiques atelier","excel-sheet-name":"Statistiques atelier","row-data":M.value,"show-checkbox":!1,"enable-filter":!1,"auto-size-columns":!0},null,8,["row-data"])])]),_:1}),l($,{class:"mt-4"},{title:c(()=>[s("div",Tt,[t[21]||(t[21]=s("i",{class:"pi pi-list text-indigo-600"},null,-1)),x(" "+a(e.$tr("Équipements en-cours")),1)])]),content:c(()=>[s("div",qt,[l(R,{"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:Y(),Equipement:Z(),client_nom:ee(),statut_reparation:te(),technicien:se(),temps_total_minutes:le(),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(J,{value:"1"},{default:c(()=>[s("div",wt,[s("div",null,[s("label",Dt,a(e.$tr("Année")),1),l(ge,{modelValue:w.value,"onUpdate:modelValue":t[6]||(t[6]=u=>w.value=u),options:X.value,optionLabel:"Annee",optionValue:"Annee",placeholder:"Année",class:"w-48",onChange:h},null,8,["modelValue","options"])]),s("div",null,[s("label",St,a(e.$tr("Commercial")),1),l(N,{modelValue:D.value,"onUpdate:modelValue":t[7]||(t[7]=u=>D.value=u),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[23]||(t[23]=s("div",{class:"h-2"},null,-1)),s("div",At,[l(be,{ref_key:"agGridCommerciaux",ref:K,localeText:e.$agGridLocale,rowData:S.value,columnDefs:pe.value,defaultColDef:ve.value,theme:e.$agGridTheme,treeData:!0,getDataPath:de,autoGroupColumnDef:me.value,groupDefaultExpanded:0,animateRows:!0,onGridReady:fe,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},null,8,["localeText","rowData","columnDefs","defaultColDef","theme","autoGroupColumnDef"])])]),_:1})]),_:1})]),_:1},8,["value"])])],2)}}};export{Mt as default};
