/*
 * 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,r,s,o,i,n,a,l,d,c){"use strict";r=__importDefault(r);class u extends s.AbstractInteractableModule{constructor(){super(...arguments),this.selectorGridderBadge=".t3js-folderStructure-badge",this.selectorOutputContainer=".t3js-folderStructure-output",this.selectorErrorContainer=".t3js-folderStructure-errors",this.selectorErrorList=".t3js-folderStructure-errors-list",this.selectorErrorFixTrigger=".t3js-folderStructure-errors-fix",this.selectorOkContainer=".t3js-folderStructure-ok",this.selectorOkList=".t3js-folderStructure-ok-list",this.selectorPermissionContainer=".t3js-folderStructure-permissions"}static removeLoadingMessage(e){e.find(".alert-loading").remove()}initialize(e){this.currentModal=e,this.getStatus(),e.on("click",this.selectorErrorFixTrigger,e=>{e.preventDefault(),this.fix()})}getStatus(){const e=this.getModalBody(),t=(0,r.default)(this.selectorGridderBadge);t.text("").hide(),e.find(this.selectorOutputContainer).empty().append(l.render(d.loading,"Loading...","")),new n(c.getUrl("folderStructureGetStatus")).get({cache:"no-cache"}).then(async r=>{const s=await r.resolve();if(e.empty().append(s.html),o.setButtons(s.buttons),!0===s.success&&Array.isArray(s.errorStatus)){let r=0;s.errorStatus.length>0?(e.find(this.selectorErrorContainer).show(),e.find(this.selectorErrorList).empty(),s.errorStatus.forEach(s=>{r++,t.text(r).show();const o=a.render(s.severity,s.title,s.message);e.find(this.selectorErrorList).append(o)})):e.find(this.selectorErrorContainer).hide()}!0===s.success&&Array.isArray(s.okStatus)&&(s.okStatus.length>0?(e.find(this.selectorOkContainer).show(),e.find(this.selectorOkList).empty(),s.okStatus.forEach(t=>{const r=a.render(t.severity,t.title,t.message);e.find(this.selectorOkList).append(r)})):e.find(this.selectorOkContainer).hide());let i=s.folderStructureFilePermissionStatus;e.find(this.selectorPermissionContainer).empty().append(a.render(i.severity,i.title,i.message)),i=s.folderStructureDirectoryPermissionStatus,e.find(this.selectorPermissionContainer).append(a.render(i.severity,i.title,i.message))},t=>{c.handleAjaxError(t,e)})}fix(){this.setModalButtonsState(!1);const e=this.getModalBody(),t=this.findInModal(this.selectorOutputContainer),r=l.render(d.loading,"Loading...","");t.empty().html(r),new n(c.getUrl("folderStructureFix")).get({cache:"no-cache"}).then(async e=>{const r=await e.resolve();u.removeLoadingMessage(t),!0===r.success&&Array.isArray(r.fixedStatus)?(r.fixedStatus.length>0?r.fixedStatus.forEach(e=>{t.append(a.render(e.severity,e.title,e.message))}):t.append(a.render(d.warning,"Nothing fixed","")),this.getStatus()):i.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)})}}return new u}));