/*
 * 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 d}from"@typo3/install/module/abstract-interactable-module.js";import m from"@typo3/backend/modal.js";import c from"@typo3/backend/notification.js";import u from"@typo3/core/ajax/ajax-request.js";import o from"@typo3/install/router.js";import h from"@typo3/core/event/regular-event.js";var l;(function(i){i.activateTrigger=".t3js-presets-activate",i.imageExecutable=".t3js-presets-image-executable",i.imageExecutableTrigger=".t3js-presets-image-executable-trigger"})(l||(l={}));class p extends d{initialize(t){super.initialize(t),this.getContent(),new h("click",s=>{s.preventDefault(),this.getCustomImagePathContent()}).delegateTo(t,l.imageExecutableTrigger),new h("click",s=>{s.preventDefault(),this.activate()}).delegateTo(t,l.activateTrigger),t.querySelectorAll(".t3js-custom-preset").forEach(s=>{new h("input",(e,a)=>{t.querySelector(`#${a.dataset.radio}`).checked=!0}).delegateTo(s,".t3js-custom-preset")})}getContent(){const t=this.getModalBody();new u(o.getUrl("presetsGetContent")).get({cache:"no-cache"}).then(async s=>{const e=await s.resolve();e.success===!0&&e.html!=="undefined"&&e.html.length>0?(t.innerHTML=e.html,m.setButtons(e.buttons)):c.error("Something went wrong","The request was not processed successfully. Please check the browser's console and TYPO3's log.")},s=>{o.handleAjaxError(s,t)})}getCustomImagePathContent(){const t=this.getModalBody(),s=this.getModuleContent().dataset.presetsContentToken;new u(o.getUrl()).post({install:{token:s,action:"presetsGetContent",values:{Image:{additionalSearchPath:this.findInModal(l.imageExecutable).value}}}}).then(async e=>{const a=await e.resolve();a.success===!0&&a.html!=="undefined"&&a.html.length>0?t.innerHTML=a.html:c.error("Something went wrong","The request was not processed successfully. Please check the browser's console and TYPO3's log.")},e=>{o.handleAjaxError(e,t)})}activate(){this.setModalButtonsState(!1);const t=this.getModalBody(),s=this.getModuleContent().dataset.presetsActivateToken,e={},a=new FormData(this.findInModal("form"));for(const[n,r]of a)e[n]=r.toString();e["install[action]"]="presetsActivate",e["install[token]"]=s,new u(o.getUrl()).post(e).then(async n=>{const r=await n.resolve();r.success===!0&&Array.isArray(r.status)?r.status.forEach(g=>{c.showMessage(g.title,g.message,g.severity)}):c.error("Something went wrong","The request was not processed successfully. Please check the browser's console and TYPO3's log.")},n=>{o.handleAjaxError(n,t)}).finally(()=>{this.setModalButtonsState(!0)})}}var f=new p;export{f as default};
