/*
 * 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{AbstractInteractableModule as T}from"@typo3/install/module/abstract-interactable-module.js";import h from"@typo3/backend/modal.js";import c from"@typo3/backend/notification.js";import u from"@typo3/core/ajax/ajax-request.js";import n from"@typo3/install/router.js";import g from"@typo3/core/event/regular-event.js";var t;(function(l){l.clearTrigger=".t3js-clearTables-clear",l.statsTrigger=".t3js-clearTables-stats",l.statContainer=".t3js-clearTables-stat-container",l.statTemplate="#t3js-clearTables-stat-template",l.statDescription=".t3js-clearTables-stat-description",l.statRows=".t3js-clearTables-stat-rows",l.statName=".t3js-clearTables-stat-name"})(t||(t={}));class b extends T{initialize(e){super.initialize(e),this.getStats(),new g("click",r=>{r.preventDefault(),e.querySelector(t.statContainer).innerHTML="",this.getStats()}).delegateTo(e,t.statsTrigger),new g("click",(r,s)=>{const a=s.closest(t.clearTrigger).dataset.table;r.preventDefault(),this.clear(a)}).delegateTo(e,t.clearTrigger)}getStats(){this.setModalButtonsState(!1);const e=this.getModalBody();new u(n.getUrl("clearTablesStats")).get({cache:"no-cache"}).then(async r=>{const s=await r.resolve();s.success===!0?(e.innerHTML=s.html,h.setButtons(s.buttons),Array.isArray(s.stats)&&s.stats.length>0&&s.stats.forEach(a=>{if(a.rowCount>0){const o=e.querySelector(t.statTemplate).content.cloneNode(!0);o.querySelector(t.statDescription).innerText=a.description,o.querySelector(t.statName).innerText=a.name,o.querySelector(t.statRows).innerText=a.rowCount,o.querySelector(t.clearTrigger).setAttribute("data-table",a.name),e.querySelector(t.statContainer).append(o)}})):c.error("Something went wrong","The request was not processed successfully. Please check the browser's console and TYPO3's log.")},r=>{n.handleAjaxError(r,e)}).finally(()=>{this.setModalButtonsState(!0)})}clear(e){const r=this.getModalBody(),s=this.getModuleContent().dataset.clearTablesClearToken;new u(n.getUrl()).post({install:{action:"clearTablesClear",token:s,table:e}}).then(async a=>{const o=await a.resolve();o.success===!0&&Array.isArray(o.status)?o.status.forEach(i=>{c.success(i.title,i.message)}):c.error("Something went wrong","The request was not processed successfully. Please check the browser's console and TYPO3's log."),this.getStats()},a=>{n.handleAjaxError(a,r)})}}var d=new b;export{d as default};
