/* * This file is part of the TYPO3 CMS project. * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 * of the License, or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. * * The TYPO3 project - inspiring people to share! */ import{LitElement as f,html as d,nothing as k}from"lit";import{property as m,state as c,customElement as y}from"lit/decorators.js";import{repeat as h}from"lit/directives/repeat.js";import g from"~labels/core.bookmarks";import u,{BookmarkStoreChangedEvent as b}from"@typo3/backend/bookmark/bookmark-store.js";import"@typo3/backend/bookmark/bookmark-manager.js";var l=function(r,t,e,s){var a=arguments.length,o=a<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,e):s,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(r,t,e,s);else for(var p=r.length-1;p>=0;p--)(i=r[p])&&(o=(a<3?i(o):a>3?i(t,e,o):i(t,e))||o);return a>3&&o&&Object.defineProperty(t,e,o),o};let n=class extends f{constructor(){super(...arguments),this.limit=0,this.groupId=null,this.groupedBookmarks=new Map,this.groups=[],this.handleStoreUpdate=()=>{this.syncFromStore()}}connectedCallback(){super.connectedCallback(),document.addEventListener(b,this.handleStoreUpdate),this.syncFromStore()}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener(b,this.handleStoreUpdate)}createRenderRoot(){return this}render(){return this.groupedBookmarks.size===0?d``:d`
${h(Array.from(this.groupedBookmarks.entries()),([t])=>t,([t,e])=>this.renderGroup(t,e,this.groupedBookmarks.size>1))}
`}async syncFromStore(){this.groupedBookmarks=await u.getGroupedBookmarks({groupId:this.groupId??void 0,limit:this.limit>0?this.limit:void 0,accessibleOnly:!0}),this.groups=await u.getGroups()}renderGroup(t,e,s){const o=this.groups.find(i=>i.id===t)?.label||g.get("notGrouped");return d`${s&&this.groupId===null?d``:k}${h(e,i=>i.id,i=>this.renderBookmarkRow(i))}
${o}
`}renderBookmarkRow(t){return d` this.handleNavigate(e,t)}> ${t.title} `}handleNavigate(t,e){t.preventDefault(),u.navigate(e)}};l([m({type:Number})],n.prototype,"limit",void 0),l([m({attribute:"group",converter:{fromAttribute:r=>{if(r===null||r==="")return null;const t=Number(r);return Number.isNaN(t)?r:t},toAttribute:r=>r===null?null:String(r)}})],n.prototype,"groupId",void 0),l([c()],n.prototype,"groupedBookmarks",void 0),l([c()],n.prototype,"groups",void 0),n=l([y("typo3-dashboard-bookmarks-widget")],n);export{n as BookmarksWidgetElement};