/*
 * 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 g}from"@typo3/install/module/abstract-interactable-module.js";import y 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 p from"@typo3/core/event/regular-event.js";var a;(function(l){l.deleteTrigger=".t3js-clearTypo3temp-delete",l.statContainer=".t3js-clearTypo3temp-stat-container",l.statsTrigger=".t3js-clearTypo3temp-stats",l.statTemplate="#t3js-clearTypo3temp-stat-template",l.statNumberOfFiles=".t3js-clearTypo3temp-stat-numberOfFiles",l.statDirectory=".t3js-clearTypo3temp-stat-directory"})(a||(a={}));class m extends g{initialize(t){super.initialize(t),this.getStats(),new p("click",o=>{o.preventDefault(),t.querySelector(a.statContainer).innerHTML="",this.getStats()}).delegateTo(t,a.statsTrigger),new p("click",(o,e)=>{o.preventDefault();const r=e.dataset.folder,s=e.dataset.storageUid!==void 0?parseInt(e.dataset.storageUid,10):void 0;this.delete(r,s)}).delegateTo(t,a.deleteTrigger)}getStats(){this.setModalButtonsState(!1);const t=this.getModalBody();new u(n.getUrl("clearTypo3tempFilesStats")).get({cache:"no-cache"}).then(async o=>{const e=await o.resolve();e.success===!0?(t.innerHTML=e.html,y.setButtons(e.buttons),Array.isArray(e.stats)&&e.stats.length>0&&e.stats.forEach(r=>{if(r.numberOfFiles>0){const s=t.querySelector(a.statTemplate).content.cloneNode(!0);s.querySelector(a.statNumberOfFiles).innerText=r.numberOfFiles,s.querySelector(a.statDirectory).innerText=r.directory,s.querySelector(a.deleteTrigger).setAttribute("data-folder",r.directory),r.storageUid!==void 0&&s.querySelector(a.deleteTrigger).setAttribute("data-storage-uid",r.storageUid),t.querySelector(a.statContainer).append(s)}})):c.error("Something went wrong","The request was not processed successfully. Please check the browser's console and TYPO3's log.")},o=>{n.handleAjaxError(o,t)}).finally(()=>{this.setModalButtonsState(!0)})}delete(t,o){const e=this.getModalBody(),r=this.getModuleContent().dataset.clearTypo3tempDeleteToken;new u(n.getUrl()).post({install:{action:"clearTypo3tempFiles",token:r,folder:t,storageUid:o}}).then(async s=>{const i=await s.resolve();i.success===!0&&Array.isArray(i.status)?(i.status.forEach(d=>{c.success(d.title,d.message)}),this.getStats()):c.error("Something went wrong","The request was not processed successfully. Please check the browser's console and TYPO3's log.")},s=>{n.handleAjaxError(s,e)})}}var T=new m;export{T as default};
