/*
 * 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/Severity","../../Router","bootstrap"],(function(e,t,s,n,r,a,o,i,c,l){"use strict";s=__importDefault(s);class m extends n.AbstractInteractableModule{constructor(){super(...arguments),this.selectorExecuteTrigger=".t3js-imageProcessing-execute",this.selectorTestContainer=".t3js-imageProcessing-twinContainer",this.selectorTwinImageTemplate=".t3js-imageProcessing-twinImage-template",this.selectorCommandContainer=".t3js-imageProcessing-command",this.selectorCommandText=".t3js-imageProcessing-command-text",this.selectorTwinImages=".t3js-imageProcessing-images"}initialize(e){this.currentModal=e,this.getData(),e.on("click",this.selectorExecuteTrigger,e=>{e.preventDefault(),this.runTests()})}getData(){const e=this.getModalBody();new o(l.getUrl("imageProcessingGetData")).get({cache:"no-cache"}).then(async t=>{const s=await t.resolve();!0===s.success?(e.empty().append(s.html),r.setButtons(s.buttons),this.runTests()):a.error("Something went wrong","The request was not processed successfully. Please check the browser's console and TYPO3's log.")},t=>{l.handleAjaxError(t,e)})}runTests(){const e=this.getModalBody(),t=this.findInModal(this.selectorExecuteTrigger);this.setModalButtonsState(!1);const n=this.findInModal(this.selectorTwinImageTemplate),r=[];e.find(this.selectorTestContainer).each((t,a)=>{const m=s.default(a),d=m.data("test"),g=i.render(c.loading,"Loading...","");m.empty().html(g);const h=new o(l.getUrl(d)).get({cache:"no-cache"}).then(async e=>{const t=await e.resolve();if(!0===t.success){m.empty(),Array.isArray(t.status)&&t.status.forEach(e=>{const t=i.render(e.severity,e.title,e.message);m.append(t)});const e=n.clone();if(e.removeClass("t3js-imageProcessing-twinImage-template"),!0===t.fileExists&&(e.find("img.reference").attr("src",t.referenceFile),e.find("img.result").attr("src",t.outputFile),e.find(this.selectorTwinImages).show()),Array.isArray(t.command)&&t.command.length>0){e.find(this.selectorCommandContainer).show();const s=[];t.command.forEach(e=>{s.push("<strong>Command:</strong>\n"+e[1]),3===e.length&&s.push("<strong>Result:</strong>\n"+e[2])}),e.find(this.selectorCommandText).html(s.join("\n"))}m.append(e)}},t=>{l.handleAjaxError(t,e)});r.push(h)}),Promise.all(r).then(()=>{t.removeClass("disabled").prop("disabled",!1)})}}return new m}));