import{f as N,af as L,o,c as r,b as s,a as c,z as O,q as R,B as n,M as W,b5 as G,F as w,A as $,E as k,i as H,d as A,b3 as J,ar as K,r as p,e as B}from"./vendor-BDR7yMJi.js";import{u as Q,S as z,a as j,s as u}from"./index-BSaHX2oa.js";import{_ as X}from"./ComboDynamique-DbhbUtR4.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"},Te={__name:"DashboardAttribution",setup(Ae){const{showSuccess:M,showError:V,showWarn:P,confirmAction:U}=Q(),v=K({lecture:!1}),f=p([]),D=p([]),g=p(""),y=p(""),T=p(""),b=p(30);let E=[];const x=B(()=>{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())}),S=B(()=>x.value.filter(t=>t.dispo)),d=async()=>{try{const{data:t}=await j.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{}},q=async t=>{const i=t.selectedTechniciens||[];if(!i.length)return;const m=i.map(_=>S.value.find(e=>e.id===_)?.nom).filter(Boolean);if(!await U({message:`Attribuer #${t.id_equipement} à ${m.join(", ")} ?`}))return;let h=0,l=[];for(const _ of i)try{const{data:e}=await j.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&&(M(`${h} attribution(s) réussie(s)`),d(),b.value=30),l.length>0&&V(l.join(`
`))},C=()=>{T.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 j.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||(P("Accès refusé"),z("DashboardAttribution"))}catch(t){V(t.response?.data?.message||t.message)}};return N(async()=>{await F(),v.lecture&&(d(),C(),E.push(setInterval(C,1e3)))}),L(()=>E.forEach(clearInterval)),(t,i)=>{const m=O,h=W,l=G,_=J;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=>R(z)("DashboardAttribution"))},null,8,["label"]),s("div",te,[s("label",se,n(t.$tr("Site"))+":",1),c(X,{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(T.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(w,null,$(f.value,e=>(o(),r("div",{key:e.id_equipement,class:k(["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(),H(l,{key:0,value:"P"+e.ordre_priorite,severity:"warn"},null,8,["value"])):A("",!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:S.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=>q(e)},null,8,["label","disabled","onClick"])])],2))),128)),f.value.length?A("",!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(w,null,$(x.value,e=>(o(),r("div",{key:e.id,class:k(["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(w,null,$(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:k(a.retard?"text-orange-500":"text-gray-400")},n(a.jours)+"j",3)]))),128))])):(o(),r("div",ke,"Aucun équipement"))],2))),128))])])])])):A("",!0)}}};export{Te as default};
