import{T as A}from"./TaskCreateDialog-BSGqPjjd.chunk.mjs";import{f as M,h as x,_ as L,e as s,N as b,i as N,C as v,j as W,k as B,r as d,o as r,c as u,l,w as n,n as h,p as g,t as p,b as k,a as E,q as P,g as $,u as _,v as z,x as O,d as U,s as I}from"./index-VLl5aIR_.chunk.mjs";import{P as S}from"./Plus-KVstq0U0.chunk.mjs";const V={name:"Dashboard",components:{NcActionButton:B,NcButton:W,Check:v,NcDashboardWidget:N,NcDashboardWidgetItem:b,TaskCreateDialog:A,Plus:S},data(){return{loading:!0,tasks:[],showAddTaskModal:!1,itemMenu:{markAsDone:{text:s("tasks","Mark as done"),icon:"icon-checkmark"}}}},computed:{...x({calendars:"getTaskCalendars"}),hasTaskToday(){return this.filteredTasks.some(a=>O(a,"today"))},filteredTasks(){return z(this.tasks.filter(a=>!a.closed))}},mounted(){this.initializeEnvironment()},methods:{t:s,...M(["toggleCompleted"]),async initializeEnvironment(){await _.connect({enableCalDAV:!0}),await this.$store.dispatch("fetchCurrentUserPrincipal");let{calendars:a}=await this.$store.dispatch("getCalendarsAndTrashBin");a=a.filter(e=>e.supportsTasks);const i=[];if(a.forEach(e=>{i.indexOf(e.owner)===-1&&i.push(e.owner)}),i.forEach(e=>{this.$store.dispatch("fetchPrincipalByUrl",{url:e})}),a.length===0){const e=this.$OCA.Theming?.color||"#0082C9";await this.$store.dispatch("appendCalendar",{displayName:s("tasks","Tasks"),color:e})}await this.fetchTasks()},async fetchTasks(){this.loading=!0;const a=await Promise.all(this.calendars.map(i=>this.$store.dispatch("getTasksFromCalendar",{calendar:i,completed:!1,related:null})));this.tasks=[...a.flat()],this.loading=!1},formatSubtext(a){return a.dueMoment.isValid()?a.allDay?a.dueMoment.calendar(null,{lastDay:s("tasks","[Due yesterday]"),sameDay:s("tasks","[Due today]"),nextDay:s("tasks","[Due tomorrow]"),lastWeek:s("tasks","[Due] L"),nextWeek:s("tasks","[Due] L"),sameElse:s("tasks","[Due] L")}):a.dueMoment.calendar(null,{lastDay:s("tasks","[Due yesterday at] LT"),sameDay:s("tasks","[Due today at] LT"),nextDay:s("tasks","[Due tomorrow at] LT"),lastWeek:s("tasks","[Due] L [at] LT"),nextWeek:s("tasks","[Due] L [at] LT"),sameElse:s("tasks","[Due] L [at] LT")}):s("tasks","No due date assigned")},getTasksAppUrl(a){return $("apps/tasks")+`/calendars/${a.calendar.id}/tasks/${a.uri}`},toggleAddTaskModel(){this.showAddTaskModal=!this.showAddTaskModal},async onMarkAsDone(a){await this.toggleCompleted(a),await this.fetchTasks()}}},j=["title"],q={key:0,class:"center-button"};function F(a,i,e,H,c,t){const m=d("Check"),y=d("NcActionButton"),T=d("NcDashboardWidgetItem"),D=d("NcDashboardWidget"),f=d("Plus"),C=d("NcButton"),w=d("TaskCreateDialog");return r(),u("div",null,[l(D,{id:"tasks_panel",items:t.filteredTasks.slice(0,t.hasTaskToday?6:4),"empty-content-message":t.t("tasks","No upcoming tasks"),"show-more-text":t.t("tasks","upcoming tasks"),loading:c.loading,"show-items-and-empty-content":!t.hasTaskToday,"half-empty-content-message":t.t("tasks","No tasks today")},{default:n(({item:o})=>[l(T,{"main-text":o.summary,"sub-text":t.formatSubtext(o),"target-url":t.getTasksAppUrl(o)},{avatar:n(()=>[E("div",{class:"calendar-dot",style:P({"background-color":o.calendar.color}),title:o.calendar.displayName},null,12,j)]),actions:n(()=>[!o.calendar.readOnly&&!(o.calendar.isSharedWithMe&&o.class!=="PUBLIC")?(r(),h(y,{key:0,"close-after-click":!0,onClick:J=>t.onMarkAsDone(o)},{icon:n(()=>[l(m,{size:20,decorative:""})]),default:n(()=>[g(" "+p(t.t("tasks","Mark as done")),1)]),_:1},8,["onClick"])):k("",!0)]),_:2},1032,["main-text","sub-text","target-url"])]),emptyContentIcon:n(()=>[l(m,{size:20,decorative:""})]),_:1},8,["items","empty-content-message","show-more-text","loading","show-items-and-empty-content","half-empty-content-message"]),c.loading?k("",!0):(r(),u("div",q,[l(C,{onClick:t.toggleAddTaskModel},{icon:n(()=>[l(f,{size:20,decorative:""})]),default:n(()=>[g(" "+p(t.t("tasks","Create a new task")),1)]),_:1},8,["onClick"]),c.showAddTaskModal?(r(),h(w,{key:0,onClose:t.toggleAddTaskModel},null,8,["onClose"])):k("",!0)]))])}const G=L(V,[["render",F]]);document.addEventListener("DOMContentLoaded",()=>{OCA.Dashboard.register("tasks",a=>U(G).use(I).mount(a))});
//# sourceMappingURL=tasks-dashboard.mjs.map
