/*! third party licenses: dist/vendor.LICENSE.txt */ import"./chunks/modulepreload-polyfill-DGCCkazm.mjs";import{D as g,M as v,U as f,X as y,F as p,b_ as o,bS as i,a6 as _,ao as w,bW as l,bZ as S,aV as n,bR as r,b$ as d}from"./core-common.mjs";import{d as k}from"./chunks/vuedraggable.umd-CKAHk2gO.mjs";import{n as b,ac as x,S as C}from"./chunks/icons-TElqpmA8.mjs";import"./chunks/sortable.esm-D5slCXxa.mjs";const W={data(){return{isMobile:this._isMobile()}},beforeMount(){window.addEventListener("resize",this._onResize)},beforeDestroy(){window.removeEventListener("resize",this._onResize)},methods:{_onResize(){this.isMobile=this._isMobile()},_isMobile(){return document.documentElement.clientWidth<768}}},N={name:"ApiDashboardWidget",components:{NcAvatar:g,NcDashboardWidget:v,NcDashboardWidgetItem:f,NcEmptyContent:y,NcButton:p,CheckIcon:x},props:{widget:{type:[Object,void 0],default:void 0},data:{type:[Object,void 0],default:void 0},loading:{type:Boolean,required:!0}},computed:{items(){var t,e;return(e=(t=this.data)==null?void 0:t.items)!=null?e:[]},emptyContentMessage(){var t,e;return(e=(t=this.data)==null?void 0:t.emptyContentMessage)!=null?e:""},halfEmptyContentMessage(){var t,e;return(e=(t=this.data)==null?void 0:t.halfEmptyContentMessage)!=null?e:""},newButton(){var t,e;return(e=(t=this.widget)==null?void 0:t.buttons)==null?void 0:e.find(s=>s.type==="new")},moreButton(){var t,e;return(e=(t=this.widget)==null?void 0:t.buttons)==null?void 0:e.find(s=>s.type==="more")},setupButton(){var t,e;return(e=(t=this.widget)==null?void 0:t.buttons)==null?void 0:e.find(s=>s.type==="setup")},showMoreLabel(){var t;return(t=this.moreButton)==null?void 0:t.text},showMoreUrl(){var t;return(t=this.moreButton)==null?void 0:t.link}}};var A=function(){var t=this,e=t._self._c;return e("NcDashboardWidget",{attrs:{items:t.items,"show-more-label":t.showMoreLabel,"show-more-url":t.showMoreUrl,loading:t.loading,"show-items-and-empty-content":!!t.halfEmptyContentMessage,"half-empty-content-message":t.halfEmptyContentMessage},scopedSlots:t._u([{key:"default",fn:function({item:s}){return[e("NcDashboardWidgetItem",{attrs:{"target-url":s.link,"overlay-icon-url":s.overlayIconUrl?s.overlayIconUrl:"","main-text":s.title,"sub-text":s.subtitle},scopedSlots:t._u([{key:"avatar",fn:function(){return[s.iconUrl?[e("NcAvatar",{attrs:{size:44,url:s.iconUrl}})]:t._e()]},proxy:!0}],null,!0)})]}},{key:"empty-content",fn:function(){return[t.items.length===0?e("NcEmptyContent",{attrs:{description:t.emptyContentMessage},scopedSlots:t._u([{key:"icon",fn:function(){return[t.emptyContentMessage?e("CheckIcon",{attrs:{size:65}}):t._e()]},proxy:!0},{key:"action",fn:function(){return[t.setupButton?e("NcButton",{attrs:{href:t.setupButton.link}},[t._v(" "+t._s(t.setupButton.text)+" ")]):t._e()]},proxy:!0}],null,!1,3234715105)}):t._e()]},proxy:!0}])})},I=[],M=b(N,A,I,!1,null,"122699a9");const O=M.exports,h=o("dashboard","panels"),D=o("dashboard","firstRun"),L={weather:{text:i("dashboard","Weather"),icon:"icon-weather-status"},status:{text:i("dashboard","Status")}},E={name:"DashboardApp",components:{ApiDashboardWidget:O,NcButton:p,Draggable:k,NcModal:_,Pencil:C,NcUserStatusIcon:w},mixins:[W],data(){var t,e;return{isAdmin:l().isAdmin,timer:new Date,registeredStatus:[],callbacks:{},callbacksStatus:{},allCallbacksStatus:{},statusInfo:L,enabledStatuses:o("dashboard","statuses"),panels:h,firstRun:D,displayName:(t=l())==null?void 0:t.displayName,uid:(e=l())==null?void 0:e.uid,layout:o("dashboard","layout").filter(s=>h[s]),modal:!1,appStoreUrl:S("/settings/apps/dashboard"),appStoreEnabled:o("dashboard","appStoreEnabled",!0),statuses:{},apiWidgets:[],apiWidgetItems:{},loadingItems:!0}},computed:{greeting(){const t=this.timer.getHours();let e;t>=22||t<5?e="night":t>=18?e="evening":t>=12?e="afternoon":e="morning";const s={morning:{generic:i("dashboard","Good morning"),withName:i("dashboard","Good morning, {name}",{name:this.displayName},void 0,{escape:!1})},afternoon:{generic:i("dashboard","Good afternoon"),withName:i("dashboard","Good afternoon, {name}",{name:this.displayName},void 0,{escape:!1})},evening:{generic:i("dashboard","Good evening"),withName:i("dashboard","Good evening, {name}",{name:this.displayName},void 0,{escape:!1})},night:{generic:i("dashboard","Hello"),withName:i("dashboard","Hello, {name}",{name:this.displayName},void 0,{escape:!1})}};return{text:this.displayName&&this.uid!==this.displayName?s[e].withName:s[e].generic}},isActive(){return t=>this.layout.indexOf(t.id)>-1},isStatusActive(){return t=>this.enabledStatuses.findIndex(e=>e===t)!==-1},sortedAllStatuses(){return Object.keys(this.allCallbacksStatus).slice().sort(this.sortStatuses)},sortedPanels(){return Object.values(this.panels).sort((t,e)=>{const s=this.layout.indexOf(t.id),a=this.layout.indexOf(e.id);return s===-1||a===-1?a-s||t.id-e.id:s-a||t.id-e.id})},sortedRegisteredStatus(){return this.registeredStatus.slice().sort(this.sortStatuses)}},watch:{callbacks(){this.rerenderPanels()},callbacksStatus(){for(const t in this.callbacksStatus){const e=this.$refs["status-"+t];this.statuses[t]&&this.statuses[t].mounted||(e?(this.callbacksStatus[t](e[0]),n.set(this.statuses,t,{mounted:!0})):console.error("Failed to register panel in the frontend as no backend data was provided for "+t))}}},async created(){await this.fetchApiWidgets();const t=Object.values(this.apiWidgets).filter(e=>this.isApiWidgetV2(e.id)).map(e=>e.id);await Promise.all(t.map(e=>this.fetchApiWidgetItems([e],!0)));for(const e of Object.values(this.apiWidgets))e.reload_interval>0&&setInterval(async()=>{await this.fetchApiWidgetItems([e.id],!0)},e.reload_interval*1e3)},mounted(){this.updateSkipLink(),window.addEventListener("scroll",this.handleScroll),setInterval(()=>{this.timer=new Date},3e4),this.firstRun&&window.addEventListener("scroll",this.disableFirstrunHint)},destroyed(){window.removeEventListener("scroll",this.handleScroll)},methods:{t:i,register(t,e){n.set(this.callbacks,t,e)},registerStatus(t,e){n.set(this.allCallbacksStatus,t,e),this.isStatusActive(t)&&(this.registeredStatus.push(t),this.$nextTick(()=>{n.set(this.callbacksStatus,t,e)}))},rerenderPanels(){for(const t in this.callbacks){if(this.isApiWidgetV2(this.panels[t].id))continue;const e=this.$refs[t];this.layout.indexOf(t)!==-1&&(this.panels[t]&&this.panels[t].mounted||(e?(this.callbacks[t](e[0],{widget:this.panels[t]}),n.set(this.panels[t],"mounted",!0)):console.error("Failed to register panel in the frontend as no backend data was provided for "+t)))}},saveLayout(){r.post(d("/apps/dashboard/api/v3/layout"),{layout:this.layout})},saveStatuses(){r.post(d("/apps/dashboard/api/v3/statuses"),{statuses:this.enabledStatuses})},showModal(){this.modal=!0,this.firstRun=!1},closeModal(){this.modal=!1},updateCheckbox(t,e){const s=this.layout.indexOf(t.id);!e&&s>-1?this.layout.splice(s,1):this.layout.push(t.id),n.set(this.panels[t.id],"mounted",!1),this.saveLayout(),this.$nextTick(()=>this.rerenderPanels())},disableFirstrunHint(){window.removeEventListener("scroll",this.disableFirstrunHint),setTimeout(()=>{this.firstRun=!1},1e3)},updateSkipLink(){document.getElementsByClassName("skip-navigation")[0].setAttribute("href","#app-dashboard")},updateStatusCheckbox(t,e){e?this.enableStatus(t):this.disableStatus(t)},enableStatus(t){this.enabledStatuses.push(t),this.registerStatus(t,this.allCallbacksStatus[t]),this.saveStatuses()},disableStatus(t){const e=this.enabledStatuses.findIndex(a=>a===t);e!==-1&&this.enabledStatuses.splice(e,1);const s=this.registeredStatus.findIndex(a=>a===t);s!==-1&&(this.registeredStatus.splice(s,1),n.set(this.statuses,t,{mounted:!1}),this.$nextTick(()=>{n.delete(this.callbacksStatus,t)})),this.saveStatuses()},sortStatuses(t,e){const s=t.toLowerCase(),a=e.toLowerCase();return s>a?1:s70?document.body.classList.add("dashboard--scrolled"):document.body.classList.remove("dashboard--scrolled")},async fetchApiWidgets(){const t=await r.get(d("/apps/dashboard/api/v1/widgets"));this.apiWidgets=t.data.ocs.data},async fetchApiWidgetItems(t,e=!1){try{const s=d("/apps/dashboard/api/v2/widget-items"),a=new URLSearchParams(t.map(m=>["widgets[]",m])),c=(await r.get("".concat(s,"?").concat(a.toString()))).data.ocs.data;e?this.apiWidgetItems=Object.assign({},this.apiWidgetItems,c):this.apiWidgetItems=c}finally{this.loadingItems=!1}},isApiWidgetV2(t){for(const e of Object.values(this.apiWidgets))if(e.id===t&&e.item_api_versions.includes(2))return!0;return!1}}};var B=function(){var t=this,e=t._self._c;return e("div",{attrs:{id:"app-dashboard"}},[e("h2",[t._v(t._s(t.greeting.text))]),e("ul",{staticClass:"statuses"},t._l(t.sortedRegisteredStatus,function(s){return e("li",{key:s,attrs:{id:"status-"+s}},[e("div",{ref:"status-"+s,refInFor:!0})])}),0),e("Draggable",t._b({staticClass:"panels",attrs:{handle:".panel--header"},on:{end:t.saveLayout},model:{value:t.layout,callback:function(s){t.layout=s},expression:"layout"}},"Draggable",{swapThreshold:.3,delay:500,delayOnTouchOnly:!0,touchStartThreshold:3},!1),[t._l(t.layout,function(s){return[t.isApiWidgetV2(t.panels[s].id)?e("div",{key:"".concat(t.panels[s].id,"-v2"),staticClass:"panel"},[e("div",{staticClass:"panel--header"},[e("h2",[e("span",{class:t.apiWidgets[t.panels[s].id].icon_class,attrs:{"aria-labelledby":"panel-".concat(t.panels[s].id,"--header--icon--description"),"aria-hidden":"true",role:"img"}}),t._v(" "+t._s(t.apiWidgets[t.panels[s].id].title)+" ")]),e("span",{staticClass:"hidden-visually",attrs:{id:"panel-".concat(t.panels[s].id,"--header--icon--description")}},[t._v(" "+t._s(t.t("dashboard",'"{title} icon"',{title:t.apiWidgets[t.panels[s].id].title}))+" ")])]),e("div",{staticClass:"panel--content"},[e("ApiDashboardWidget",{attrs:{widget:t.apiWidgets[t.panels[s].id],data:t.apiWidgetItems[t.panels[s].id],loading:t.loadingItems}})],1)]):e("div",{key:t.panels[s].id,staticClass:"panel"},[e("div",{staticClass:"panel--header"},[e("h2",[e("span",{class:t.panels[s].iconClass,attrs:{"aria-labelledby":"panel-".concat(t.panels[s].id,"--header--icon--description"),"aria-hidden":"true",role:"img"}}),t._v(" "+t._s(t.panels[s].title)+" ")]),e("span",{staticClass:"hidden-visually",attrs:{id:"panel-".concat(t.panels[s].id,"--header--icon--description")}},[t._v(" "+t._s(t.t("dashboard",'"{title} icon"',{title:t.panels[s].title}))+" ")])]),e("div",{staticClass:"panel--content",class:{loading:!t.panels[s].mounted}},[e("div",{ref:t.panels[s].id,refInFor:!0,attrs:{"data-id":t.panels[s].id}})])])]})],2),e("div",{staticClass:"footer"},[e("NcButton",{on:{click:t.showModal},scopedSlots:t._u([{key:"icon",fn:function(){return[e("Pencil",{attrs:{size:20}})]},proxy:!0}])},[t._v(" "+t._s(t.t("dashboard","Customize"))+" ")])],1),t.modal?e("NcModal",{attrs:{size:"large"},on:{close:t.closeModal}},[e("div",{staticClass:"modal__content"},[e("h2",[t._v(t._s(t.t("dashboard","Edit widgets")))]),e("ol",{staticClass:"panels"},t._l(t.sortedAllStatuses,function(s){return e("li",{key:s,class:"panel-"+s},[e("input",{staticClass:"checkbox",attrs:{id:"status-checkbox-"+s,type:"checkbox"},domProps:{checked:t.isStatusActive(s)},on:{input:function(a){return t.updateStatusCheckbox(s,a.target.checked)}}}),e("label",{attrs:{for:"status-checkbox-"+s}},[s==="status"?e("NcUserStatusIcon",{attrs:{status:"online","aria-hidden":"true"}}):e("span",{class:t.statusInfo[s].icon,attrs:{"aria-hidden":"true"}}),t._v(" "+t._s(t.statusInfo[s].text)+" ")],1)])}),0),e("Draggable",t._b({staticClass:"panels",attrs:{tag:"ol",handle:".draggable"},on:{end:t.saveLayout},model:{value:t.layout,callback:function(s){t.layout=s},expression:"layout"}},"Draggable",{swapThreshold:.3,delay:500,delayOnTouchOnly:!0,touchStartThreshold:3},!1),t._l(t.sortedPanels,function(s){return e("li",{key:s.id,class:"panel-"+s.id},[e("input",{staticClass:"checkbox",attrs:{id:"panel-checkbox-"+s.id,type:"checkbox"},domProps:{checked:t.isActive(s)},on:{input:function(a){return t.updateCheckbox(s,a.target.checked)}}}),e("label",{class:{draggable:t.isActive(s)},attrs:{for:"panel-checkbox-"+s.id}},[e("span",{class:s.iconClass,attrs:{"aria-hidden":"true"}}),t._v(" "+t._s(s.title)+" ")])])}),0),t.isAdmin&&t.appStoreEnabled?e("a",{staticClass:"button",attrs:{href:t.appStoreUrl}},[t._v(t._s(t.t("dashboard","Get more widgets from the App Store")))]):t._e(),t.statuses.weather&&t.isStatusActive("weather")?e("div",[e("h2",[t._v(t._s(t.t("dashboard","Weather service")))]),e("p",[t._v(" "+t._s(t.t("dashboard","For your privacy, the weather data is requested by your Nextcloud server on your behalf so the weather service receives no personal information."))+" ")]),e("p",{staticClass:"credits--end"},[e("a",{attrs:{href:"https://api.met.no/doc/TermsOfService",target:"_blank",rel:"noopener"}},[t._v(t._s(t.t("dashboard","Weather data from Met.no")))]),t._v(", "),e("a",{attrs:{href:"https://wiki.osmfoundation.org/wiki/Privacy_Policy",target:"_blank",rel:"noopener"}},[t._v(t._s(t.t("dashboard","geocoding with Nominatim")))]),t._v(", "),e("a",{attrs:{href:"https://www.opentopodata.org/#public-api",target:"_blank",rel:"noopener"}},[t._v(t._s(t.t("dashboard","elevation data from OpenTopoData")))]),t._v(". ")])]):t._e()],1)]):t._e()],1)},$=[],P=b(E,B,$,!1,null,"062db4c1");const R=P.exports,T=n.extend(R),u=new T({}).$mount("#app-content-vue");window.OCA.Dashboard={register:(t,e)=>u.register(t,e),registerStatus:(t,e)=>u.registerStatus(t,e)};