/*
 * 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"bootstrap";import{AbstractInteractableModule as g}from"@typo3/install/module/abstract-interactable-module.js";import f from"@typo3/backend/modal.js";import p from"@typo3/backend/notification.js";import c from"@typo3/core/ajax/ajax-request.js";import{InfoBox as u}from"@typo3/install/renderable/info-box.js";import h from"@typo3/install/renderable/severity.js";import r from"@typo3/install/router.js";import x from"@typo3/core/event/regular-event.js";var n;(function(l){l.checkTrigger=".t3js-extensionCompatTester-check",l.uninstallTrigger=".t3js-extensionCompatTester-uninstall",l.outputContainer=".t3js-extensionCompatTester-output"})(n||(n={}));class m extends g{initialize(t){super.initialize(t),this.loadModuleFrameAgnostic("@typo3/install/renderable/info-box.js").then(()=>{this.getLoadedExtensionList()}),new x("click",()=>{this.findInModal(n.uninstallTrigger)?.classList?.add("hidden");const s=this.findInModal(n.outputContainer);s&&(s.innerHTML=""),this.getLoadedExtensionList()}).delegateTo(t,n.checkTrigger),new x("click",(s,a)=>{this.uninstallExtension(a.dataset.extension)}).delegateTo(t,n.uninstallTrigger)}getLoadedExtensionList(){this.setModalButtonsState(!1);const t=this.getModalBody(),s=this.findInModal(n.outputContainer);s&&this.renderProgressBar(s,{},"append"),new c(r.getUrl("extensionCompatTesterLoadedExtensionList")).get({cache:"no-cache"}).then(async a=>{const o=await a.resolve();t.innerHTML=o.html,f.setButtons(o.buttons);const e=this.findInModal(n.outputContainer);this.renderProgressBar(e,{},"append"),o.success===!0?this.loadExtLocalconf().then(()=>{e.append(u.create(h.ok,"ext_localconf.php of all loaded extensions successfully loaded"))},async i=>{this.renderFailureMessages("ext_localconf.php",(await i.response.json()).brokenExtensions,e)}).finally(()=>{this.unlockModal()}):(p.error("Something went wrong","The request was not processed successfully. Please check the browser's console and TYPO3's log."),this.unlockModal())},a=>{r.handleAjaxError(a,t),this.unlockModal()})}unlockModal(){this.findInModal(n.outputContainer)?.querySelector("typo3-backend-progress-bar")?.remove(),this.setModalButtonsState(!0)}renderFailureMessages(t,s,a){for(const o of s){let e;o.isProtected||(e=document.createElement("button"),e.classList.add("btn","btn-danger","t3js-extensionCompatTester-uninstall"),e.dataset.extension=o.name,e.innerText='Uninstall extension "'+o.name+'"'),a.append(u.create(h.error,"Loading "+t+' of extension "'+o.name+'" failed',o.isProtected?"Extension is mandatory and cannot be uninstalled.":""),e)}this.unlockModal()}loadExtLocalconf(){const t=this.getModuleContent().dataset.extensionCompatTesterLoadExt_localconfToken;return new c(r.getUrl()).post({install:{action:"extensionCompatTesterLoadExtLocalconf",token:t}})}uninstallExtension(t){const s=this.getModuleContent().dataset.extensionCompatTesterUninstallExtensionToken,a=this.getModalBody(),o=this.findInModal(n.outputContainer);this.renderProgressBar(o,{},"append"),new c(r.getUrl()).post({install:{action:"extensionCompatTesterUninstallExtension",token:s,extension:t}}).then(async e=>{const i=await e.resolve();i.success?(Array.isArray(i.status)&&i.status.forEach(d=>{a.querySelector(n.outputContainer).replaceChildren(u.create(d.severity,d.title,d.message))}),this.findInModal(n.uninstallTrigger).classList.add("hidden"),this.getLoadedExtensionList()):p.error("Something went wrong","The request was not processed successfully. Please check the browser's console and TYPO3's log.")},e=>{r.handleAjaxError(e,a)})}}var T=new m;export{T as default};
