import{b as N,g as L,U as O,ac as R}from"./primevue-CfIk0_DY.js";import{u as W,S as B,b as w,s as u}from"./index-BxIwIJfy.js";import{C as G}from"./ComboDynamique-BzWI4ISP.js";import{o as H,P as J,b as o,c as r,d as s,v as c,a7 as K,t as n,F as $,C as k,q as A,k as Q,p as j,E as X,a as p,y as P}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";const Y={key:0,class:"p-4 bg-gray-50 h-[calc(100vh-120px)]"},Z={class:"flex justify-between items-center mb-3"},ee={class:"flex gap-2"},te={class:"flex items-center gap-2 ml-4"},se={class:"text-sm text-gray-600"},ie={class:"flex items-center gap-2 ml-4"},ne={class:"text-sm text-gray-600"},ae={class:"text-sm text-gray-400"},oe={class:"grid grid-cols-1 lg:grid-cols-2 gap-4 h-[calc(100%-50px)]"},le={class:"bg-white rounded shadow flex flex-col h-full overflow-hidden"},re={class:"p-3 border-b flex justify-between items-center shrink-0",style:{"margin-bottom":"12px"}},ce={class:"font-semibold text-gray-700"},ue={class:"p-4 overflow-y-auto flex-1"},de={class:"flex justify-between mb-1"},pe={class:"font-medium"},me={class:"flex gap-1"},he={class:"text-sm text-gray-600 mb-2"},_e={class:"flex gap-2 items-center"},ve={key:0,class:"text-center py-6 text-gray-400"},fe={class:"bg-white rounded shadow flex flex-col h-full overflow-hidden"},be={class:"p-3 border-b flex justify-between items-center shrink-0",style:{"margin-bottom":"12px"}},ge={class:"font-semibold text-gray-700"},ye={class:"p-4 overflow-y-auto flex-1"},xe={class:"flex justify-between mb-1"},we={class:"font-medium"},$e={key:0,class:"space-y-2 mt-2"},ke={key:1,class:"text-sm text-gray-400 italic"},Ie={__name:"DashboardAttribution",setup(Ae){const{showSuccess:U,showError:C,showWarn:q,confirmAction:z}=W(),v=X({lecture:!1}),f=p([]),D=p([]),g=p(""),y=p(""),V=p(""),b=p(30);let T=[];const x=P(()=>{const t=new Map;return D.value.forEach(i=>{t.has(i.id_utilisateur)||t.set(i.id_utilisateur,{id:i.id_utilisateur,nom:i.technicien_nom,dispo:i.disponible===1,equipements:[]}),i.id_equipement&&t.get(i.id_utilisateur).equipements.push({id:i.id_equipement,desc:i.equipement_description,jours:i.jours_en_cours,retard:i.en_retard===1})}),Array.from(t.values())}),E=P(()=>x.value.filter(t=>t.dispo)),d=async()=>{try{const{data:t}=await w.post(`${u.lienApi}/dashboardAttribution/${u.db}`,{id_site_atelier:g.value||null,id_equipement:y.value||null});t.success&&(f.value=(t.equipementsEnAttente||[]).map(i=>({...i,selectedTechniciens:[]})),D.value=t.techniciensStatut||[])}catch{}},M=async t=>{const i=t.selectedTechniciens||[];if(!i.length)return;const m=i.map(_=>E.value.find(e=>e.id===_)?.nom).filter(Boolean);if(!await z({message:`Attribuer #${t.id_equipement} à ${m.join(", ")} ?`}))return;let h=0,l=[];for(const _ of i)try{const{data:e}=await w.post(`${u.lienApi}/attribuerEquipement/${u.db}/${_}`,{id_equipement:t.id_equipement});e.success?h++:l.push(e.message)}catch(e){const a=e.response?.data;let I=a?.message||e.message;a?.equipementsEnCours?.length&&(I+=" ("+a.equipementsEnCours.join(", ")+")"),l.push(I)}h>0&&(U(`${h} attribution(s) réussie(s)`),d(),b.value=30),l.length>0&&C(l.join(`
`))},S=()=>{V.value=new Date().toLocaleTimeString("fr-FR",{hour:"2-digit",minute:"2-digit"}),--b.value<=0&&(d(),b.value=30)},F=async()=>{try{const{data:t}=await w.post(`${u.lienApi}/verifierDroit/${u.state.dbCommun6}`,{id_utilisateur:u.userId,id_page:1005,mail:u.state.userCloud.mail});v.lecture=t?.lecture||!1,v.lecture||(q("Accès refusé"),B("DashboardAttribution"))}catch(t){C(t.response?.data?.message||t.message)}};return H(async()=>{await F(),v.lecture&&(d(),S(),T.push(setInterval(S,1e3)))}),J(()=>T.forEach(clearInterval)),(t,i)=>{const m=N,h=L,l=O,_=R;return v.lecture?(o(),r("div",Y,[s("div",Z,[s("div",ee,[c(m,{label:t.$tr("Actualiser"),icon:"pi pi-refresh",onClick:d},null,8,["label"]),c(m,{label:t.$tr("Fermer"),icon:"pi pi-times",text:"",onClick:i[0]||(i[0]=e=>K(B)("DashboardAttribution"))},null,8,["label"]),s("div",te,[s("label",se,n(t.$tr("Site"))+":",1),c(G,{size:"small",modelValue:g.value,"onUpdate:modelValue":[i[1]||(i[1]=e=>g.value=e),d],placeholder:t.$tr("Tous"),table:"site",ajouter:!1,style:{"min-width":"150px"}},null,8,["modelValue","placeholder"])]),s("div",ie,[s("label",ne,n(t.$tr("ID Équipement"))+":",1),c(h,{size:"small",modelValue:y.value,"onUpdate:modelValue":[i[2]||(i[2]=e=>y.value=e),d],placeholder:t.$tr("Tous"),style:{width:"120px"}},null,8,["modelValue","placeholder"])])]),s("span",ae,n(V.value)+" ("+n(b.value)+"s)",1)]),s("div",oe,[s("div",le,[s("div",re,[s("span",ce,n(t.$tr("En attente")),1),c(l,{value:f.value.length,severity:"secondary"},null,8,["value"])]),s("div",ue,[(o(!0),r($,null,k(f.value,e=>(o(),r("div",{key:e.id_equipement,class:A(["border rounded",e.heures_attente>24?"border-orange-300 bg-orange-50":""]),style:{"margin-bottom":"12px",padding:"16px"}},[s("div",de,[s("span",pe,"#"+n(e.id_equipement),1),s("div",me,[e.ordre_priorite?(o(),Q(l,{key:0,value:"P"+e.ordre_priorite,severity:"warn"},null,8,["value"])):j("",!0),c(l,{value:e.heures_attente+"h",severity:e.heures_attente>24?"warn":"secondary"},null,8,["value","severity"])])]),s("div",he,n(e.client_nom)+" - "+n(e.description),1),s("div",_e,[c(_,{modelValue:e.selectedTechniciens,"onUpdate:modelValue":a=>e.selectedTechniciens=a,options:E.value,optionLabel:"nom",optionValue:"id",placeholder:t.$tr("Sélectionner techniciens"),size:"small",class:"flex-1",style:{"min-width":"200px"}},null,8,["modelValue","onUpdate:modelValue","options","placeholder"]),c(m,{icon:"pi pi-check",label:t.$tr("Attribuer"),size:"small",disabled:!e.selectedTechniciens?.length,onClick:a=>M(e)},null,8,["label","disabled","onClick"])])],2))),128)),f.value.length?j("",!0):(o(),r("div",ve," Aucun "))])]),s("div",fe,[s("div",be,[s("span",ge,n(t.$tr("Techniciens")),1),c(l,{value:x.value.length,severity:"secondary"},null,8,["value"])]),s("div",ye,[(o(!0),r($,null,k(x.value,e=>(o(),r("div",{key:e.id,class:A(["border rounded",e.dispo?"border-green-300":""]),style:{"margin-bottom":"12px",padding:"16px"}},[s("div",xe,[s("span",we,n(e.nom),1),c(l,{value:e.dispo?"Disponible":"Occupé",severity:e.dispo?"success":"info"},null,8,["value","severity"])]),e.equipements.length?(o(),r("div",$e,[(o(!0),r($,null,k(e.equipements,a=>(o(),r("div",{key:a.id,class:"text-sm p-2 bg-gray-50 rounded flex justify-between"},[s("span",null,"#"+n(a.id)+" "+n(a.desc),1),s("span",{class:A(a.retard?"text-orange-500":"text-gray-400")},n(a.jours)+"j",3)]))),128))])):(o(),r("div",ke,"Aucun équipement"))],2))),128))])])])])):j("",!0)}}};export{Ie as default};
