import{f as q,$ as m,g as C,o as w,c as x,b as n,a as i,z as O,q as S,j as M,E as U,aL as W,aM as K,d as Y,r as a,e as E,ar as J}from"./vendor-0kGcmQpG.js";import{_ as P,u as Q,s,a as $,S as j}from"./index-Bn9WoKhP.js";const X={class:"w-full flex flex-col h-screen"},Z={class:"flex min-w-full flex-col lg:flex-row lg:items-center gap-2 p-1"},ee={class:"btns flex items-center gap-2 lg:w-1/2 lg:justify-start"},te={class:"flex items-center gap-3 lg:w-1/2 lg:justify-end whitespace-nowrap"},ae={key:0,class:"grow overflow-auto"},le={key:1,class:"grow overflow-auto"},se={class:"h-full"},oe={class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},ne={__name:"MesEvenements",setup(re){const{showError:A,showWarn:F}=Q(),u=a(),g=a(),f=a([]),k=a("1"),R=a(),h=a([]),_=a([]),c=a({dataSource:[]}),v=a({value:0}),B=[{label:"Calendrier",value:0,icon:"pi pi-calendar"},{label:"Agenda",value:1,icon:"pi pi-list"}],o=J({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1}),z=a([{field:"Subject",headerName:"Événement",width:400,sortable:!0,filter:"agTextColumnFilter",cellRenderer:e=>`<div class="flex items-center gap-2">
        <i class="pi pi-calendar text-blue-500"></i>
        <span class="font-medium">${e.value||""}</span>
      </div>`},{field:"formattedDate",headerName:"Date",width:150,sortable:!0,filter:"agDateColumnFilter",cellStyle:{textAlign:"center"},cellRenderer:e=>`<span class="px-2 py-1 bg-blue-100 text-blue-800 rounded-full text-sm font-medium">${e.value||""}</span>`},{field:"StartTime",headerName:"Heure",width:120,sortable:!0,filter:"agTextColumnFilter",cellStyle:{textAlign:"center"},valueFormatter:e=>b(e.value),cellRenderer:e=>`<span class="px-2 py-1 bg-green-100 text-green-800 rounded-full text-sm font-medium">${b(e.value)}</span>`}]),I=a({sortable:!0,filter:"agTextColumnFilter",floatingFilter:!1,resizable:!0,suppressHeaderMenuButton:!0,minWidth:100}),D=()=>{if(!u.value?.api||!l.value||l.value.length===0)return[];let e=0;return u.value.api.forEachNodeAfterFilter(t=>{t.data&&e++}),[{Subject:`${e} Événement(s)`,formattedDate:"",StartTime:""}]},N=e=>{g.value=e.api,setTimeout(()=>{g.value&&l.value&&l.value.length>0&&(g.value.sizeColumnsToFit(),f.value=D())},100)},y=()=>{u.value?.api&&l.value&&l.value.length>0&&setTimeout(()=>{f.value=D()},0)},V=E(()=>!c.value.dataSource||c.value.dataSource.length===0?[]:c.value.dataSource.map(e=>({start:m(e.StartTime).format("YYYY-MM-DD"),end:m(e.EndTime).format("YYYY-MM-DD"),title:e.Subject,class:"event-custom",allDay:e.IsAllDay||!0}))),l=E(()=>c.value.dataSource.map(e=>({...e,formattedDate:m(e.StartTime).format("DD/MM/YYYY")}))),b=e=>m(e).format("HH:mm"),G=async()=>{try{const t=(await $.post(`${s.lienApi}/verifierDroit/${s.state.dbCommun6}`,{id_utilisateur:s.userId,id_page:1208,mail:s.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;t&&Object.keys(t).length>0&&(o.lecture=t.lecture,o.ajout=t.ajout,o.modif=t.modif,o.supp=t.supp,o.devalidation=t.devalidation,o.validation=t.validation),o.lecture||(F("Vous n'avez pas le droit, veuillez consulter l'administrateur"),j("MesEvenements"))}catch(e){A("Une erreur est survenue : "+(e.response?.data?.message||e.message))}finally{s.state.afficher_in_progress=!1}};q(async()=>{await G(),await T()});const T=async()=>{s.state.afficher_in_progress=!0;try{const{data:e}=await $.post(`${s.lienApi}/CrmPlanning/${s.db}`,{IDcommercial:R.value,action:k.value},{headers:{"Content-Type":"application/json"}});h.value=e,_.value=[],h.value.length>0&&h.value.forEach((t,p)=>{const d=m(t.Date);_.value.push({Id:p,IsAllDay:!0,Subject:t.Libelle,StartTime:d.toDate(),EndTime:d.toDate(),formattedDate:d.format("DD/MM/YYYY")})}),c.value.dataSource=_.value,setTimeout(()=>{u.value?.api&&l.value&&l.value.length>0&&(f.value=D())},100)}catch{}finally{s.state.afficher_in_progress=!1}};return(e,t)=>{const p=O,d=C("Tooltip"),H=W,L=C("ag-grid-vue");return w(),x("div",X,[n("div",Z,[n("div",ee,[i(p,{icon:"pi pi-refresh",label:"Afficher",text:"",onClick:t[0]||(t[0]=r=>T())}),i(p,{icon:"pi pi-times",label:"Fermer",text:"",onClick:t[1]||(t[1]=r=>S(j)("MesEvenements"))})]),n("div",te,[i(H,{modelValue:v.value,"onUpdate:modelValue":t[2]||(t[2]=r=>v.value=r),options:B,dataKey:"value"},{option:M(r=>[i(d,{value:r.option.label},{default:M(()=>[n("i",{class:U([r.option.icon,"text-xl"])},null,2)]),_:2},1032,["value"])]),_:1},8,["modelValue"])])]),t[3]||(t[3]=n("div",{class:"h-2"},null,-1)),v.value.value===0?(w(),x("div",ae,[i(S(K),{events:V.value,"active-view":"month","disable-views":["years","year","day"],"editable-events":!1,"drag-to-create-event":!1,"on-event-click":!1,"events-on-month-view":!0,time:!1,locale:"fr",style:{height:"100%"}},null,8,["events"])])):Y("",!0),v.value.value===1?(w(),x("div",le,[n("div",se,[n("div",oe,[i(L,{ref_key:"agGridRef",ref:u,rowData:l.value,columnDefs:z.value,defaultColDef:I.value,theme:e.$agGridTheme,localeText:e.$agGridLocale,pinnedBottomRowData:f.value,onGridReady:N,onFilterChanged:y,onSortChanged:y,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},null,8,["rowData","columnDefs","defaultColDef","theme","localeText","pinnedBottomRowData"])])])])):Y("",!0)])}}},ce=P(ne,[["__scopeId","data-v-c13a6e70"]]);export{ce as default};
