/*
 * 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!
 */
var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};define(["require","exports","jquery","../AbstractInteractableModule","TYPO3/CMS/Backend/Modal","TYPO3/CMS/Backend/Notification","TYPO3/CMS/Core/Ajax/AjaxRequest","../../Renderable/InfoBox","../../Renderable/ProgressBar","../../Renderable/Severity","../../Router","bootstrap"],(function(e,t,n,s,o,a,i,l,r,d,c){"use strict";n=__importDefault(n);class u extends s.AbstractInteractableModule{constructor(){super(...arguments),this.selectorCheckTrigger=".t3js-extensionCompatTester-check",this.selectorUninstallTrigger=".t3js-extensionCompatTester-uninstall",this.selectorOutputContainer=".t3js-extensionCompatTester-output"}initialize(e){this.currentModal=e,this.getLoadedExtensionList(),e.on("click",this.selectorCheckTrigger,()=>{this.findInModal(this.selectorUninstallTrigger).addClass("hidden"),this.findInModal(this.selectorOutputContainer).empty(),this.getLoadedExtensionList()}),e.on("click",this.selectorUninstallTrigger,e=>{this.uninstallExtension((0,n.default)(e.target).data("extension"))})}getLoadedExtensionList(){this.setModalButtonsState(!1),this.findInModal(".modal-loading").hide();const e=this.getModalBody(),t=this.findInModal(this.selectorOutputContainer),n=r.render(d.loading,"Loading...","");t.append(n),new i(c.getUrl("extensionCompatTesterLoadedExtensionList")).get({cache:"no-cache"}).then(async t=>{const n=await t.resolve();e.empty().append(n.html),o.setButtons(n.buttons);const s=this.findInModal(this.selectorOutputContainer),i=r.render(d.loading,"Loading...","");s.append(i),!0===n.success?this.loadExtLocalconf().then(()=>{s.append(l.render(d.ok,"ext_localconf.php of all loaded extensions successfully loaded","")),this.loadExtTables().then(()=>{s.append(l.render(d.ok,"ext_tables.php of all loaded extensions successfully loaded",""))},async e=>{this.renderFailureMessages("ext_tables.php",(await e.response.json()).brokenExtensions,s)}).finally(()=>{this.unlockModal()})},async e=>{this.renderFailureMessages("ext_localconf.php",(await e.response.json()).brokenExtensions,s),s.append(l.render(d.notice,"Skipped scanning ext_tables.php files due to previous errors","")),this.unlockModal()}):a.error("Something went wrong","The request was not processed successfully. Please check the browser's console and TYPO3's log.")},t=>{c.handleAjaxError(t,e)})}unlockModal(){this.findInModal(this.selectorOutputContainer).find(".alert-loading").remove(),this.findInModal(this.selectorCheckTrigger).removeClass("disabled").prop("disabled",!1)}renderFailureMessages(e,t,s){for(let o of t){let t;o.isProtected||(t=(0,n.default)("<button />",{class:"btn btn-danger t3js-extensionCompatTester-uninstall"}).attr("data-extension",o.name).text('Uninstall extension "'+o.name+'"')),s.append(l.render(d.error,"Loading "+e+' of extension "'+o.name+'" failed',o.isProtected?"Extension is mandatory and cannot be uninstalled.":""),t)}this.unlockModal()}loadExtLocalconf(){const e=this.getModuleContent().data("extension-compat-tester-load-ext_localconf-token");return new i(c.getUrl()).post({install:{action:"extensionCompatTesterLoadExtLocalconf",token:e}})}loadExtTables(){const e=this.getModuleContent().data("extension-compat-tester-load-ext_tables-token");return new i(c.getUrl()).post({install:{action:"extensionCompatTesterLoadExtTables",token:e}})}uninstallExtension(e){const t=this.getModuleContent().data("extension-compat-tester-uninstall-extension-token"),s=this.getModalBody(),o=(0,n.default)(this.selectorOutputContainer),u=r.render(d.loading,"Loading...","");o.append(u),new i(c.getUrl()).post({install:{action:"extensionCompatTesterUninstallExtension",token:t,extension:e}}).then(async e=>{const t=await e.resolve();t.success?(Array.isArray(t.status)&&t.status.forEach(e=>{const t=l.render(e.severity,e.title,e.message);s.find(this.selectorOutputContainer).empty().append(t)}),this.findInModal(this.selectorUninstallTrigger).addClass("hidden"),this.getLoadedExtensionList()):a.error("Something went wrong","The request was not processed successfully. Please check the browser's console and TYPO3's log.")},e=>{c.handleAjaxError(e,s)})}}return new u}));