import{f as k,$ as s,g as I,o as v,c as b,b as u,a as l,z as A,q as _,j as D,E as O,aL as R,aM as N,d as S,r as o,e as x}from"./vendor-BDR7yMJi.js";import{_ as V,s as d,a as B,S as G}from"./index-BSaHX2oa.js";import{_ as L}from"./DataGrid-DbeHIyBR.js";import"./useAgGridConfig-DxO2r97K.js";const P={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"},H={class:"btns flex items-center gap-2 lg:w-1/2 lg:justify-start"},q={class:"flex items-center gap-3 lg:w-1/2 lg:justify-end whitespace-nowrap"},F={key:0,class:"grow overflow-auto"},K={key:1,class:"grow overflow-auto",style:{height:"100%",width:"100%"}},U={__name:"MesEvenementsCrm",setup(J){const y=o(),w=o(),h=o("1"),Y=o(),f=o([]),p=o([]),n=o({dataSource:[]}),m=o({value:0}),M=[{label:"Calendrier",value:0,icon:"pi pi-calendar"},{label:"Agenda",value:1,icon:"pi pi-list"}],T=e=>typeof e=="string"&&e.includes(",")?"Toute la journée":s(e).format("HH:mm"),j={Subject: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>`,formattedDate:e=>`<span class="px-2 py-1 bg-blue-100 text-blue-800 rounded-full text-sm font-medium">${e.value||""}</span>`,StartTime:e=>`<span class="px-2 py-1 bg-green-100 text-green-800 rounded-full text-sm font-medium">${T(e.value)}</span>`},C=e=>{w.value=e.api},E=x(()=>!n.value.dataSource||n.value.dataSource.length===0?[]:n.value.dataSource.map(e=>{let t;if(typeof e.StartTime=="string"&&e.StartTime.includes(",")){const a=e.StartTime.split(",").map(Number);t=s(new Date(a[0],a[1]-1,a[2]))}else e.dateObj?t=s(e.dateObj):t=s(e.StartTime);return{start:t.format("YYYY-MM-DD"),end:t.format("YYYY-MM-DD"),title:e.Subject,class:"event-crm",allDay:e.IsAllDay||!0}})),$=x(()=>n.value.dataSource.map(e=>{let t;if(e.dateObj)t=s(e.dateObj).format("DD/MM/YYYY");else if(typeof e.StartTime=="string"&&e.StartTime.includes(",")){const a=e.StartTime.split(",").map(Number);t=s(new Date(a[0],a[1]-1,a[2])).format("DD/MM/YYYY")}else t=s(e.StartTime).format("DD/MM/YYYY");return{...e,formattedDate:t}}));k(async()=>{await g()});const g=async()=>{d.state.afficher_in_progress=!0;try{const{data:e}=await B.post(`${d.lienApi}/CrmPlanning/${d.db}`,{IDcommercial:Y.value,action:h.value},{headers:{"Content-Type":"application/json"}});f.value=e,p.value=[],f.value.length>0&&f.value.forEach((t,a)=>{const i=s(t.Date).format("YYYY,MM,DD"),c=i.split(",").map(Number);p.value.push({Id:a,IsAllDay:!0,Subject:t.Libelle,StartTime:i,EndTime:i,dateObj:new Date(c[0],c[1]-1,c[2])})}),n.value.dataSource=p.value}catch{}finally{d.state.afficher_in_progress=!1}};return(e,t)=>{const a=A,i=I("Tooltip"),c=R;return v(),b("div",P,[u("div",z,[u("div",H,[l(a,{icon:"pi pi-refresh",label:"Afficher",text:"",onClick:t[0]||(t[0]=r=>g())}),l(a,{icon:"pi pi-times",label:"Fermer",text:"",onClick:t[1]||(t[1]=r=>_(G)("MesEvenementsCrm"))})]),u("div",q,[l(c,{modelValue:m.value,"onUpdate:modelValue":t[2]||(t[2]=r=>m.value=r),options:M,dataKey:"value"},{option:D(r=>[l(i,{value:r.option.label},{default:D(()=>[u("i",{class:O([r.option.icon,"text-xl"])},null,2)]),_:2},1032,["value"])]),_:1},8,["modelValue"])])]),t[3]||(t[3]=u("div",{class:"h-2"},null,-1)),m.value.value===0?(v(),b("div",F,[l(_(N),{events:E.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"])])):S("",!0),m.value.value===1?(v(),b("div",K,[l(L,{ref_key:"agGridRef",ref:y,"excel-file-name":"Mes evenements CRM","excel-sheet-name":"Mes evenements CRM","row-data":$.value,"excluded-columns":["Id","IsAllDay","EndTime","dateObj"],"column-order":["Subject","formattedDate","StartTime"],"column-widths":{Subject:400,formattedDate:150,StartTime:120},"custom-renderers":j,"enable-totals":!1,onGridReady:C},null,8,["row-data"])])):S("",!0)])}}},ee=V(U,[["__scopeId","data-v-34f5abdb"]]);export{ee as default};
