/*
 * 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 u from"@typo3/core/ajax/ajax-request.js";import g from"@typo3/core/event/regular-event.js";import c from"@typo3/backend/icons.js";import m from"@typo3/backend/storage/persistent.js";import d from"@typo3/backend/viewport.js";import{AjaxResponse as p}from"@typo3/core/ajax/ajax-response.js";var a;(function(o){o.element="#typo3-cms-backend-backend-toolbaritems-systeminformationtoolbaritem",o.icon="#typo3-cms-backend-backend-toolbaritems-systeminformationtoolbaritem .toolbar-item-icon .t3js-icon",o.menu="#typo3-cms-backend-backend-toolbaritems-systeminformationtoolbaritem .dropdown-menu",o.data="[data-systeminformation-data]",o.badge="[data-systeminformation-badge]",o.message="[data-systeminformation-message-module]",o.messageLink="[data-systeminformation-message-module] a"})(a||(a={}));class r{constructor(){this.timer=null,this.updateMenu=async()=>{const t=document.querySelector(a.icon),e=t.cloneNode(!0);this.timer!==null&&(clearTimeout(this.timer),this.timer=null),c.getIcon("spinner-circle",c.sizes.small).then(s=>{t.replaceWith(document.createRange().createContextualFragment(s))});try{const n=await(await new u(TYPO3.settings.ajaxUrls.systeminformation_render).get({redirect:"manual"})).resolve();document.querySelector(a.menu).innerHTML=n,r.updateBadge()}catch(s){if(!(s instanceof p&&s.response.type==="opaqueredirect"))throw s}finally{document.querySelector(a.icon).replaceWith(e),this.timer=setTimeout(this.updateMenu,1e3*300)}},new g("click",this.handleMessageLinkClick).delegateTo(document,a.messageLink),d.Topbar.Toolbar.registerEvent(this.updateMenu),document.addEventListener("typo3:system-information-menu:update",()=>this.updateMenu())}static getData(){const e=document.querySelector(a.data)?.dataset;return{count:e?.systeminformationDataCount?parseInt(e.systeminformationDataCount,10):0,severityBadgeClass:e?.systeminformationDataSeveritybadgeclass??""}}static getMessageDataFromElement(t){const e=t.dataset;return{count:e.systeminformationMessageCount?parseInt(e.systeminformationMessageCount,10):0,status:e.systeminformationMessageStatus??"",module:e.systeminformationMessageModule??"",params:e.systeminformationMessageParams??""}}static updateBadge(){const t=r.getData(),e=document.querySelector(a.badge);e.removeAttribute("class"),e.classList.add("toolbar-item-badge"),e.classList.add("badge"),e.classList.add("badge-pill"),t.severityBadgeClass!==""&&e.classList.add(t.severityBadgeClass),e.textContent=t.count.toString(),e.classList.toggle("hidden",!(t.count>0))}handleMessageLinkClick(t,e){const s=r.getMessageDataFromElement(e.closest(a.message));if(s.module==="")return;t.preventDefault(),t.stopPropagation();const n={},l=Math.floor(Date.now()/1e3);let i={};m.isset("systeminformation")&&(i=JSON.parse(m.get("systeminformation"))),n[s.module]={lastAccess:l},Object.assign(i,n),m.set("systeminformation",JSON.stringify(i)).then(()=>{TYPO3.ModuleMenu.App.showModule(s.module,s.params),d.Topbar.refresh()})}}var f=new r;export{f as default};
