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