/*
 * 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 h from"@typo3/core/document-service.js";import l from"@typo3/core/event/regular-event.js";import r from"@typo3/core/ajax/ajax-request.js";import d from"@typo3/install/module/password-strength.js";import{InfoBox as u}from"@typo3/install/renderable/info-box.js";import"@typo3/backend/element/icon-element.js";import{selector as m}from"@typo3/core/literals.js";import"@typo3/backend/element/progress-bar-element.js";var n;(function(i){i.body=".t3js-body",i.moduleContent=".t3js-module-content",i.mainContent=".t3js-installer-content",i.progressBar=".t3js-installer-progress",i.databaseConnectOutput=".t3js-installer-databaseConnect-output",i.databaseSelectOutput=".t3js-installer-databaseSelect-output",i.databaseDataOutput=".t3js-installer-databaseData-output"})(n||(n={}));class g{constructor(){this.initializeEvents(),h.ready().then(()=>{this.initialize()})}initializeEvents(){new l("click",e=>{e.preventDefault(),this.showEnvironmentAndFolders()}).delegateTo(document,".t3js-installer-environmentFolders-retry"),new l("click",e=>{e.preventDefault(),this.executeEnvironmentAndFolders()}).delegateTo(document,".t3js-installer-environmentFolders-execute"),new l("click",e=>{e.preventDefault(),this.executeDatabaseConnect()}).delegateTo(document,".t3js-installer-databaseConnect-execute"),new l("click",e=>{e.preventDefault(),this.executeDatabaseSelect()}).delegateTo(document,".t3js-installer-databaseSelect-execute"),new l("click",e=>{e.preventDefault(),this.executeDatabaseData()}).delegateTo(document,".t3js-installer-databaseData-execute"),new l("click",e=>{e.preventDefault(),this.executeDefaultConfiguration()}).delegateTo(document,".t3js-installer-defaultConfiguration-execute"),new l("click",(e,t)=>{e.preventDefault();const a=document.querySelector(t.dataset.toggleTarget);t.dataset.toggleState==="invisible"?(t.dataset.toggleState="visible",a.setAttribute("type","text")):(t.dataset.toggleState="invisible",a.setAttribute("type","password"))}).delegateTo(document,".t3-install-form-password-toggle"),new l("change",(e,t)=>{const a=t.value;document.querySelectorAll(".t3-install-driver-data").forEach(s=>s.setAttribute("hidden","")),document.querySelectorAll(".t3-install-driver-data input").forEach(s=>s.setAttribute("disabled","disabled")),document.querySelectorAll(m`#${a} input`).forEach(s=>s.removeAttribute("disabled")),document.querySelector("#"+a)?.removeAttribute("hidden")}).delegateTo(document,"#t3js-connect-database-driver")}initialize(){this.setProgress(0),this.getMainLayout()}getUrl(e){let t=location.href;return t=t.replace(location.search,""),e!==void 0&&(t=t+"?install[action]="+e),t}setProgress(e){const t=document.querySelector(n.progressBar);t!==null&&e!==0&&(t.value=e,t.label=`Step ${e} of 5 completed`)}getMainLayout(){new r(this.getUrl("mainLayout")).get({cache:"no-cache"}).then(async e=>{const t=await e.resolve();document.querySelector(n.body).innerHTML=t.html,this.checkInstallerAvailable()})}checkInstallerAvailable(){new r(this.getUrl("checkInstallerAvailable")).get({cache:"no-cache"}).then(async e=>{(await e.resolve()).success?this.checkEnvironmentAndFolders():this.showInstallerNotAvailable()})}showInstallerNotAvailable(){const e=document.querySelector(n.mainContent);new r(this.getUrl("showInstallerNotAvailable")).get({cache:"no-cache"}).then(async t=>{const a=await t.resolve();a.success===!0&&(e.innerHTML=a.html)})}checkEnvironmentAndFolders(){this.setProgress(1),new r(this.getUrl("checkEnvironmentAndFolders")).get({cache:"no-cache"}).then(async e=>{(await e.resolve()).success===!0?this.checkTrustedHostsPattern():this.showEnvironmentAndFolders()})}showEnvironmentAndFolders(){const e=document.querySelector(n.mainContent);new r(this.getUrl("showEnvironmentAndFolders")).get({cache:"no-cache"}).then(async t=>{const a=await t.resolve();if(a.success===!0){e.innerHTML=a.html;const s=document.querySelector(".t3js-installer-environment-details");let o=!1;Array.isArray(a.environmentStatusErrors)&&a.environmentStatusErrors.forEach(c=>{o=!0,s.append(u.create(c.severity,c.title,c.message))}),Array.isArray(a.environmentStatusWarnings)&&a.environmentStatusWarnings.forEach(c=>{o=!0,s.append(u.create(c.severity,c.title,c.message))}),Array.isArray(a.structureErrors)&&a.structureErrors.forEach(c=>{o=!0,s.append(u.create(c.severity,c.title,c.message))}),o?(s.removeAttribute("hidden"),document.querySelectorAll(".t3js-installer-environmentFolders-bad").forEach(c=>c.removeAttribute("hidden"))):document.querySelectorAll(".t3js-installer-environmentFolders-good").forEach(c=>c.removeAttribute("hidden"))}})}executeEnvironmentAndFolders(){new r(this.getUrl("executeEnvironmentAndFolders")).get({cache:"no-cache"}).then(async e=>{(await e.resolve()).success===!0&&this.checkTrustedHostsPattern()})}checkTrustedHostsPattern(){new r(this.getUrl("checkTrustedHostsPattern")).get({cache:"no-cache"}).then(async e=>{(await e.resolve()).success===!0?this.checkDatabaseConnect():this.executeAdjustTrustedHostsPattern()})}executeAdjustTrustedHostsPattern(){new r(this.getUrl("executeAdjustTrustedHostsPattern")).get({cache:"no-cache"}).then(()=>{this.checkDatabaseConnect()})}checkDatabaseConnect(){this.setProgress(2),new r(this.getUrl("checkDatabaseConnect")).get({cache:"no-cache"}).then(async e=>{(await e.resolve()).success===!0?this.checkDatabaseSelect():this.showDatabaseConnect()})}showDatabaseConnect(){const e=document.querySelector(n.mainContent);new r(this.getUrl("showDatabaseConnect")).get({cache:"no-cache"}).then(async t=>{const a=await t.resolve();a.success===!0&&(e.innerHTML=a.html,document.querySelector("#t3js-connect-database-driver").dispatchEvent(new Event("change",{bubbles:!0})),d.initialize(document.querySelector(".t3-install-form-password-strength")))})}executeDatabaseConnect(){const e=document.querySelector(n.databaseConnectOutput),t={"install[action]":"executeDatabaseConnect","install[token]":document.querySelector(n.moduleContent).dataset.installerDatabaseConnectExecuteToken};for(const[a,s]of new FormData(document.querySelector(n.body+" form")))t[a]=s.toString();new r(this.getUrl()).post(t).then(async a=>{const s=await a.resolve();s.success===!0?this.checkDatabaseSelect():Array.isArray(s.status)&&(e.replaceChildren(),s.status.forEach(o=>{e.append(u.create(o.severity,o.title,o.message))}))})}checkDatabaseSelect(){this.setProgress(3),new r(this.getUrl("checkDatabaseSelect")).get({cache:"no-cache"}).then(async e=>{(await e.resolve()).success===!0?this.checkDatabaseData():this.showDatabaseSelect()})}showDatabaseSelect(){const e=document.querySelector(n.mainContent);new r(this.getUrl("showDatabaseSelect")).get({cache:"no-cache"}).then(async t=>{const a=await t.resolve();a.success===!0&&(e.innerHTML=a.html)})}executeDatabaseSelect(){const e=document.querySelector(n.databaseSelectOutput),t={"install[action]":"executeDatabaseSelect","install[token]":document.querySelector(n.moduleContent).dataset.installerDatabaseSelectExecuteToken};for(const[a,s]of new FormData(document.querySelector(n.body+" form")))t[a]=s.toString();new r(this.getUrl()).post(t).then(async a=>{const s=await a.resolve();s.success===!0?this.checkDatabaseRequirements():Array.isArray(s.status)&&s.status.forEach(o=>{e.replaceChildren(u.create(o.severity,o.title,o.message))})})}checkDatabaseRequirements(){const e=document.querySelector(n.databaseSelectOutput),t={"install[action]":"checkDatabaseRequirements","install[token]":document.querySelector(n.moduleContent).dataset.installerDatabaseCheckRequirementsExecuteToken};for(const[a,s]of new FormData(document.querySelector(n.body+" form")))t[a]=s.toString();new r(this.getUrl()).post(t).then(async a=>{const s=await a.resolve();s.success===!0?this.checkDatabaseData():Array.isArray(s.status)&&(e.replaceChildren(),s.status.forEach(o=>{e.append(u.create(o.severity,o.title,o.message))}))})}checkDatabaseData(){this.setProgress(4),new r(this.getUrl("checkDatabaseData")).get({cache:"no-cache"}).then(async e=>{(await e.resolve()).success===!0?this.showDefaultConfiguration():this.showDatabaseData()})}showDatabaseData(){const e=document.querySelector(n.mainContent);new r(this.getUrl("showDatabaseData")).get({cache:"no-cache"}).then(async t=>{const a=await t.resolve();a.success===!0&&(e.innerHTML=a.html,d.initialize(document.querySelector(".t3-install-form-password-strength")))})}executeDatabaseData(){const e=document.querySelector(n.databaseDataOutput),t={"install[action]":"executeDatabaseData","install[token]":document.querySelector(n.moduleContent).dataset.installerDatabaseDataExecuteToken};for(const[s,o]of new FormData(document.querySelector(n.body+" form")))t[s]=o.toString();const a=document.createElement("typo3-backend-progress-bar");e.replaceChildren(a),new r(this.getUrl()).post(t).then(async s=>{const o=await s.resolve();o.success===!0?this.showDefaultConfiguration():Array.isArray(o.status)&&(e.replaceChildren(),o.status.forEach(c=>{e.append(u.create(c.severity,c.title,c.message))}))})}showDefaultConfiguration(){const e=document.querySelector(n.mainContent);this.setProgress(5),new r(this.getUrl("showDefaultConfiguration")).get({cache:"no-cache"}).then(async t=>{const a=await t.resolve();a.success===!0&&(e.innerHTML=a.html)})}executeDefaultConfiguration(){const e={"install[action]":"executeDefaultConfiguration","install[token]":document.querySelector(n.moduleContent).dataset.installerDefaultConfigurationExecuteToken};for(const[t,a]of new FormData(document.querySelector(n.body+" form")))e[t]=a.toString();new r(this.getUrl()).post(e).then(async t=>{const a=await t.resolve();top.location.href=a.redirect})}}var f=new g;export{f as default};
