import{w as P,f as G,$ as r,g as Y,o as y,c as S,b as s,a as i,z as L,q as M,ax as q,j,E as H,aL as U,aM as K,d as N,r as l,e as V}from"./vendor-0kGcmQpG.js";import{_ as W}from"./ComboDynamique-CzrtYPe1.js";import{_ as J,s as h,a as Q,S as X}from"./index-Bn9WoKhP.js";const Z={class:"w-full flex flex-col h-screen"},ee={class:"flex min-w-full flex-col lg:flex-row lg:items-center gap-2 p-1"},te={class:"btns flex items-center gap-2 lg:w-1/4 lg:justify-start"},ae={class:"flex items-center gap-3 lg:w-2/4 lg:justify-center px-4"},le={class:"w-48"},oe={class:"w-48"},se={class:"flex items-center gap-3 lg:w-1/4 lg:justify-end whitespace-nowrap"},ne={key:0,class:"flex-grow overflow-auto"},re={key:1,class:"flex-grow overflow-auto"},ie={class:"h-full"},ue={class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},ce={__name:"Planning",setup(de){const u=l(),_=l(),f=l([]),p=l("1"),v=l(),x=l([]),w=l([]),c=l({dataSource:[]}),g=l({value:0}),$=[{label:"Calendrier",value:0,icon:"pi pi-calendar"},{label:"Agenda",value:1,icon:"pi pi-list"}],R=[{id:"1",text:"Tous les Actions"},{id:"2",text:"Rendez-Vous"}],A=l([{field:"Subject",headerName:"Événement",width:350,sortable:!0,filter:"agTextColumnFilter",cellRenderer:e=>`<div class="flex items-center gap-2">
        <i class="pi pi-calendar text-orange-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-orange-100 text-orange-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=>C(e.value),cellRenderer:e=>`<span class="px-2 py-1 bg-green-100 text-green-800 rounded-full text-sm font-medium">${C(e.value)}</span>`},{field:"commercial",headerName:"Commercial",width:200,sortable:!0,filter:"agTextColumnFilter",cellRenderer:e=>`<div class="flex items-center gap-2">
        <i class="pi pi-user text-blue-500"></i>
        <span class="font-medium">${z(e.data)}</span>
      </div>`}]),F=l({sortable:!0,filter:"agTextColumnFilter",floatingFilter:!1,resizable:!0,suppressHeaderMenuButton:!0,minWidth:100}),D=()=>{if(!u.value?.api||!n.value||n.value.length===0)return[];let e=0;return u.value.api.forEachNodeAfterFilter(t=>{t.data&&e++}),[{Subject:`${e} Planning(s)`,formattedDate:"",StartTime:"",commercial:""}]},k=e=>{_.value=e.api,setTimeout(()=>{_.value&&n.value&&n.value.length>0&&(_.value.sizeColumnsToFit(),f.value=D())},100)},T=()=>{u.value?.api&&n.value&&n.value.length>0&&setTimeout(()=>{f.value=D()},0)},B=V(()=>!c.value.dataSource||c.value.dataSource.length===0?[]:c.value.dataSource.map(e=>{let t;if(typeof e.StartTime=="string"&&e.StartTime.includes(",")){const a=e.StartTime.split(",").map(Number);t=r(new Date(a[0],a[1]-1,a[2]))}else e.dateObj?t=r(e.dateObj):t=r(e.StartTime);return{start:t.format("YYYY-MM-DD"),end:t.format("YYYY-MM-DD"),title:e.Subject,class:"event-planning",allDay:e.IsAllDay||!0}})),n=V(()=>c.value.dataSource.map(e=>{let t;if(e.dateObj)t=r(e.dateObj).format("DD/MM/YYYY");else if(typeof e.StartTime=="string"&&e.StartTime.includes(",")){const a=e.StartTime.split(",").map(Number);t=r(new Date(a[0],a[1]-1,a[2])).format("DD/MM/YYYY")}else t=r(e.StartTime).format("DD/MM/YYYY");return{...e,formattedDate:t}})),C=e=>typeof e=="string"&&e.includes(",")?"Toute la journée":r(e).format("HH:mm"),z=e=>e.commercial||"N/A";P([v,p],()=>{b()},{deep:!0}),G(async()=>{await b()});const b=async()=>{h.state.afficher_in_progress=!0;try{const e=await Q.post(`${h.lienApi}/CrmPlanning/${h.db}`,{IDcommercial:v.value,action:p.value},{headers:{"Content-Type":"application/json"}});x.value=e.data,w.value=[],x.value.length>0&&x.value.forEach((t,a)=>{const d=r(t.Date).format("YYYY,MM,DD"),m=d.split(",").map(Number);w.value.push({Id:a,IsAllDay:!0,Subject:t.Libelle,StartTime:d,EndTime:d,dateObj:new Date(m[0],m[1]-1,m[2]),commercial:t.Commercial||""})}),c.value.dataSource=w.value,setTimeout(()=>{u.value?.api&&n.value&&n.value.length>0&&(f.value=D())},100)}catch{}finally{h.state.afficher_in_progress=!1}};return(e,t)=>{const a=L,d=W,m=q,E=Y("Tooltip"),I=U,O=Y("ag-grid-vue");return y(),S("div",Z,[s("div",ee,[s("div",te,[i(a,{icon:"pi pi-refresh",label:"Afficher",text:"",onClick:t[0]||(t[0]=o=>b())}),i(a,{icon:"pi pi-times",label:"Fermer",text:"",onClick:t[1]||(t[1]=o=>M(X)("Planning"))})]),s("div",ae,[s("div",le,[i(d,{placeholder:"Commercial",table:"commercial",modelValue:v.value,"onUpdate:modelValue":t[2]||(t[2]=o=>v.value=o),class:"w-full"},null,8,["modelValue"])]),s("div",oe,[i(m,{size:"small",modelValue:p.value,"onUpdate:modelValue":t[3]||(t[3]=o=>p.value=o),options:R,optionLabel:"text",optionValue:"id",placeholder:"Action",class:"w-full",showClear:!0},null,8,["modelValue"])])]),s("div",se,[i(I,{modelValue:g.value,"onUpdate:modelValue":t[4]||(t[4]=o=>g.value=o),options:$,dataKey:"value"},{option:j(o=>[i(E,{value:o.option.label},{default:j(()=>[s("i",{class:H([o.option.icon,"text-xl"])},null,2)]),_:2},1032,["value"])]),_:1},8,["modelValue"])])]),t[5]||(t[5]=s("div",{class:"h-2"},null,-1)),g.value.value===0?(y(),S("div",ne,[i(M(K),{events:B.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"])])):N("",!0),g.value.value===1?(y(),S("div",re,[s("div",ie,[s("div",ue,[i(O,{ref_key:"agGridRef",ref:u,rowData:n.value,columnDefs:A.value,defaultColDef:F.value,theme:e.$agGridTheme,localeText:e.$agGridLocale,pinnedBottomRowData:f.value,onGridReady:k,onFilterChanged:T,onSortChanged:T,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},null,8,["rowData","columnDefs","defaultColDef","theme","localeText","pinnedBottomRowData"])])])])):N("",!0)])}}},ve=J(ce,[["__scopeId","data-v-884600c3"]]);export{ve as default};
