import{T as L}from"./TaskCreateDialog-oz4N92Ds.chunk.mjs";import{_ as p,c as k,o as c,a as y,g as N,h as v,e as t,y as B,z as W,C as z,k as E,A as _,r as n,q as l,b as m,w as i,p as h,x as u,t as g,B as $,f as I,n as P,D as O,E as U,d as S,s as V}from"./index-Md6Dd2Tg.chunk.mjs";import{P as q}from"./Plus-BpYRVs-r.chunk.mjs";const F={data(){return{color:"currentColor"}}},j={role:"img",class:"task-icon"},G=["width","height"],H=["fill","stroke"];function J(a,r,e,T,d,s){return c(),k("span",j,[(c(),k("svg",{width:a.size,height:a.size,viewBox:"0 0 32 32"},[y("path",{fill:d.color,stroke:d.color,"stroke-miterlimit":"10","stroke-width":".75",d:"m14.383 26.764s0.259-0.716 0.563-1.367c4.908-10.57 11.212-17.53 14.008-20.69 2.264-2.559 1.378-2.156 0.375-1.503-4.09 2.659-11.742 11.206-14.668 14.169-0.542 0.545-1.769 1.833-2.045 1.833-0.313 0-1.358-0.481-1.955-0.833-2.282-1.338-4.464-2.643-5.834-3.136-2.917-1.049-2.092-0.052-1.926 0.281 0.521 1.042 7.566 6.689 9.899 9.356 0.722 0.824 1.583 1.89 1.583 1.89z"},null,8,H)],8,G))])}const K=p(F,[["render",J],["__scopeId","data-v-b78bc47d"]]),Q={name:"Dashboard",components:{NcActionButton:_,NcButton:E,Check:z,NcDashboardWidget:W,NcDashboardWidgetItem:B,TaskCreateDialog:L,Plus:q,TaskIcon:K},data(){return{loading:!0,tasks:[],showAddTaskModal:!1,itemMenu:{markAsDone:{text:t("tasks","Mark as done"),icon:"icon-checkmark"}}}},computed:{...v({calendars:"getTaskCalendars"}),hasTaskToday(){return this.filteredTasks.some(a=>U(a,"today"))},filteredTasks(){return O(this.tasks.filter(a=>!a.closed))}},mounted(){this.initializeEnvironment()},methods:{t,...N(["toggleCompleted"]),async initializeEnvironment(){await P.connect({enableCalDAV:!0}),await this.$store.dispatch("fetchCurrentUserPrincipal");let{calendars:a}=await this.$store.dispatch("getCalendarsAndTrashBin");a=a.filter(e=>e.supportsTasks);const r=[];if(a.forEach(e=>{r.indexOf(e.owner)===-1&&r.push(e.owner)}),r.forEach(e=>{this.$store.dispatch("fetchPrincipalByUrl",{url:e})}),a.length===0){const e=this.$OCA.Theming?.color||"#0082C9";await this.$store.dispatch("appendCalendar",{displayName:t("tasks","Tasks"),color:e})}await this.fetchTasks()},async fetchTasks(){this.loading=!0;const a=await Promise.all(this.calendars.map(r=>this.$store.dispatch("getTasksFromCalendar",{calendar:r,completed:!1,related:null})));this.tasks=[...a.flat()],this.loading=!1},formatSubtext(a){return a.dueMoment.isValid()?a.allDay?a.dueMoment.calendar(null,{lastDay:t("tasks","[Due yesterday]"),sameDay:t("tasks","[Due today]"),nextDay:t("tasks","[Due tomorrow]"),lastWeek:t("tasks","[Due] L"),nextWeek:t("tasks","[Due] L"),sameElse:t("tasks","[Due] L")}):a.dueMoment.calendar(null,{lastDay:t("tasks","[Due yesterday at] LT"),sameDay:t("tasks","[Due today at] LT"),nextDay:t("tasks","[Due tomorrow at] LT"),lastWeek:t("tasks","[Due] L [at] LT"),nextWeek:t("tasks","[Due] L [at] LT"),sameElse:t("tasks","[Due] L [at] LT")}):t("tasks","No due date assigned")},getTasksAppUrl(a){return I("apps/tasks")+`/calendars/${a.calendar.id}/tasks/${a.uri}`},toggleAddTaskModel(){this.showAddTaskModal=!this.showAddTaskModal},async onMarkAsDone(a){await this.toggleCompleted(a),await this.fetchTasks()}}},R=["title"],X={key:0,class:"center-button"};function Y(a,r,e,T,d,s){const D=n("Check"),f=n("NcActionButton"),C=n("NcDashboardWidgetItem"),w=n("TaskIcon"),A=n("NcDashboardWidget"),M=n("Plus"),b=n("NcButton"),x=n("TaskCreateDialog");return c(),k("div",null,[l(A,{id:"tasks_panel",items:s.filteredTasks.slice(0,s.hasTaskToday?6:4),"empty-content-message":s.t("tasks","No upcoming tasks"),"show-more-text":s.t("tasks","upcoming tasks"),loading:d.loading,"show-items-and-empty-content":!s.hasTaskToday,"half-empty-content-message":s.t("tasks","No tasks today")},{default:i(({item:o})=>[l(C,{"main-text":o.summary,"sub-text":s.formatSubtext(o),"target-url":s.getTasksAppUrl(o)},{avatar:i(()=>[y("div",{class:"calendar-dot",style:$({"background-color":o.calendar.color}),title:o.calendar.displayName},null,12,R)]),actions:i(()=>[!o.calendar.readOnly&&!(o.calendar.isSharedWithMe&&o.class!=="PUBLIC")?(c(),h(f,{key:0,"close-after-click":!0,onClick:aa=>s.onMarkAsDone(o)},{icon:i(()=>[l(D,{size:20,decorative:""})]),default:i(()=>[u(" "+g(s.t("tasks","Mark as done")),1)]),_:1},8,["onClick"])):m("",!0)]),_:2},1032,["main-text","sub-text","target-url"])]),emptyContentIcon:i(()=>[l(w)]),_:1},8,["items","empty-content-message","show-more-text","loading","show-items-and-empty-content","half-empty-content-message"]),d.loading?m("",!0):(c(),k("div",X,[l(b,{onClick:s.toggleAddTaskModel},{icon:i(()=>[l(M,{size:20,decorative:""})]),default:i(()=>[u(" "+g(s.t("tasks","Create a new task")),1)]),_:1},8,["onClick"]),d.showAddTaskModal?(c(),h(x,{key:0,onClose:s.toggleAddTaskModel},null,8,["onClose"])):m("",!0)]))])}const Z=p(Q,[["render",Y]]);document.addEventListener("DOMContentLoaded",()=>{OCA.Dashboard.register("tasks",a=>S(Z).use(V).mount(a))});
//# sourceMappingURL=tasks-dashboard.mjs.map
