import{r as o,w as x,f as L,g as J,o as S,i as K,j as D,b as l,c as O,B as n,d as P,a as v,aw as Q,z as X,S as Y}from"./vendor-BDR7yMJi.js";import{_ as Z,u as ee,d as te,a as se,s as E}from"./index-BSaHX2oa.js";const le={class:"flex flex-col h-full"},ae={key:0,class:"p-2 sm:p-3 bg-blue-50 rounded mb-3 sm:mb-4"},oe={class:"flex items-center gap-2"},ie={class:"font-medium text-sm sm:text-base"},ne={class:"flex flex-col sm:flex-row justify-between sm:items-center mb-3 sm:mb-4 gap-2"},re={class:"flex items-center gap-2"},ue={class:"text-sm sm:text-base"},ce={class:"text-gray-600"},me={style:{height:"400px",width:"100%"}},de={class:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-2 sm:gap-0"},fe={class:"text-gray-600"},pe={class:"flex gap-2 w-full sm:w-auto"},ve={__name:"SelectEquipements",props:{show:Boolean,codeClient:String,tousEquipements:{type:Boolean,default:!1},filtreNbc:{type:Boolean,default:!1},filtreNdevis:{type:Boolean,default:!1},filtreNfacturec:{type:Boolean,default:!1},IDcommercial:{type:[Number,String],default:null}},emits:["close","equipementsImportes"],setup(q,{emit:$}){const{showError:N,showSuccess:B,showWarn:k}=ee(),{tr:a}=te(),t=q,h=$,u=o(!1),r=o(),y=o(!1),g=o(!1),f=o([]),i=o([]),c=o(!1),V=o({mode:"multiRow",checkboxes:!0,headerCheckbox:!0}),I=o([{field:"id_equipement",headerName:a("N°"),width:80},{field:"client_nom",headerName:a("Client"),width:200},{field:"marque",headerName:a("Marque"),width:150},{field:"modele",headerName:a("Modèle"),width:150},{field:"numero_serie",headerName:a("N° série"),width:140},{field:"statut_libelle",headerName:a("Statut Final"),width:200},{field:"date_creation",headerName:a("Date création"),width:120,valueFormatter:e=>e.value?new Date(e.value).toLocaleDateString("fr-FR"):""}]),A=o({sortable:!0,filter:"agTextColumnFilter",floatingFilter:!1,resizable:!0,suppressHeaderMenuButton:!0,minWidth:80}),T=e=>{r.value=e.api,setTimeout(()=>{r.value&&r.value.sizeColumnsToFit()},100)},z=()=>{if(!r.value)return;const e=r.value.getSelectedNodes();i.value=e.map(m=>m.data);const s=f.value.length;c.value=s>0&&i.value.length===s};x(()=>t.show,e=>{u.value=e},{immediate:!0}),x(()=>u.value,e=>{!e&&t.show&&h("close")});const C=async()=>{y.value=!0;try{const e={code_client:t.codeClient||"",date_debut:null,date_fin:null,tous:t.tousEquipements,filtreNbc:t.filtreNbc,filtreNdevis:t.filtreNdevis,filtreNfacturec:t.filtreNfacturec,IDcommercial:t.IDcommercial},s=await se.post(`${E.lienApi}/equipementsTermines/${E.db}`,e);f.value=s.data,i.value=[],c.value=!1}catch(e){N(a("Erreur lors du chargement des équipements")+" : "+e.message)}finally{y.value=!1}},F=()=>{r.value&&(c.value?r.value.selectAll():r.value.deselectAll())},R=async()=>{if(i.value.length===0){k(a("Veuillez sélectionner au moins un équipement"));return}g.value=!0;try{h("equipementsImportes",i.value),B(`${i.value.length} ${a("équipement(s) importé(s) avec succès")}`),b()}catch(e){N(a("Erreur lors de l'importation")+" : "+e.message)}finally{g.value=!1}},b=()=>{u.value=!1,h("close")};return x(()=>[t.tousEquipements,t.codeClient,t.show,t.filtreNbc,t.filtreNdevis,t.filtreNfacturec,t.IDcommercial],([e,s,m,w,p,_,d],[G,M,,j,W,H,U])=>{m&&(e!==G||s!==M||w!==j||p!==W||_!==H||d!==U)&&C()}),L(async()=>{await C()}),(e,s)=>{const m=Q,w=J("AgGridVue"),p=X,_=Y;return S(),K(_,{visible:u.value,"onUpdate:visible":s[1]||(s[1]=d=>u.value=d),modal:"",header:q.tousEquipements?e.$tr("Sélectionner des équipements"):e.$tr("Sélectionner des équipements terminés à livrer"),style:{width:"95vw",maxWidth:"90vw",height:"85vh"},maximizable:!0,onHide:b,closable:!0},{footer:D(()=>[l("div",de,[l("div",fe,n(i.value.length)+" "+n(e.$tr("équipement(s) sélectionné(s)")),1),l("div",pe,[v(p,{label:e.$tr("Annuler"),icon:"pi pi-times",onClick:b,severity:"secondary",class:"flex-1 sm:flex-none text-xs sm:text-sm"},null,8,["label"]),v(p,{label:e.$tr("Importer"),icon:"pi pi-check",onClick:R,disabled:i.value.length===0,loading:g.value,class:"flex-1 sm:flex-none text-xs sm:text-sm"},null,8,["label","disabled","loading"])])])]),default:D(()=>[l("div",le,[t.codeClient?(S(),O("div",ae,[l("div",oe,[s[2]||(s[2]=l("i",{class:"pi pi-user text-blue-600"},null,-1)),l("span",ie,n(e.$tr("Client"))+": "+n(t.codeClient),1)])])):P("",!0),l("div",ne,[l("div",re,[v(m,{modelValue:c.value,"onUpdate:modelValue":s[0]||(s[0]=d=>c.value=d),onChange:F,binary:""},null,8,["modelValue"]),l("label",ue,n(e.$tr("Tout sélectionner"))+" ("+n(i.value.length)+" "+n(e.$tr("sélectionné(s)"))+")",1)]),l("div",ce,n(f.value.length)+" "+n(e.$tr("équipement(s) trouvé(s)")),1)]),l("div",me,[v(w,{rowData:f.value,columnDefs:I.value,defaultColDef:A.value,rowSelection:V.value,onGridReady:T,onSelectionChanged:z,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},null,8,["rowData","columnDefs","defaultColDef","rowSelection"])])])]),_:1},8,["visible","header"])}}},be=Z(ve,[["__scopeId","data-v-e145b94e"]]);export{be as S};
