/*
 * 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 c from"@typo3/backend/modal.js";import l from"@typo3/backend/notification.js";import u from"@typo3/core/ajax/ajax-request.js";import o from"@typo3/install/router.js";import m from"@typo3/install/module/password-strength.js";import{AbstractInteractableModule as h}from"@typo3/install/module/abstract-interactable-module.js";import p from"@typo3/core/event/regular-event.js";var e;(function(t){t.adminCreateButton=".t3js-createAdmin-create",t.adminUserInput=".t3js-createAdmin-user",t.adminRealNameInput=".t3js-createAdmin-realname",t.adminPasswordInput=".t3js-createAdmin-password",t.adminPasswordCheckInput=".t3js-createAdmin-password-check",t.adminEmailInput=".t3js-createAdmin-email",t.adminSysMaintainterInput=".t3js-createAdmin-system-maintainer"})(e||(e={}));class f extends h{initialize(a){super.initialize(a),this.getData(),new p("click",s=>{s.preventDefault(),this.create()}).delegateTo(a,e.adminCreateButton)}getData(){const a=this.getModalBody();new u(o.getUrl("createAdminGetData")).get({cache:"no-cache"}).then(async s=>{const r=await s.resolve();r.success===!0?(a.innerHTML=r.html,m.initialize(a.querySelector(".t3-install-form-password-strength")),c.setButtons(r.buttons)):l.error("Something went wrong","The request was not processed successfully. Please check the browser's console and TYPO3's log.")},s=>{o.handleAjaxError(s,a)})}create(){this.setModalButtonsState(!1);const a=this.getModalBody(),r={install:{action:"createAdmin",token:this.getModuleContent().dataset.createAdminToken,userName:this.findInModal(e.adminUserInput).value,userPassword:this.findInModal(e.adminPasswordInput).value,userPasswordCheck:this.findInModal(e.adminPasswordCheckInput).value,userEmail:this.findInModal(e.adminEmailInput).value,realName:this.findInModal(e.adminRealNameInput).value,userSystemMaintainer:this.findInModal(e.adminSysMaintainterInput).checked?1:0}};this.getModuleContent().querySelectorAll("input").forEach(n=>{n.disabled=!0}),new u(o.getUrl()).post(r).then(async n=>{const i=await n.resolve();i.success===!0&&Array.isArray(i.status)?(i.status.forEach(d=>{l.showMessage(d.title,d.message,d.severity)}),i.userCreated&&(this.findInModal(e.adminUserInput).value="",this.findInModal(e.adminPasswordInput).value="",this.findInModal(e.adminPasswordCheckInput).value="",this.findInModal(e.adminEmailInput).value="",this.findInModal(e.adminSysMaintainterInput).checked=!1)):l.error("Something went wrong","The request was not processed successfully. Please check the browser's console and TYPO3's log.")},n=>{o.handleAjaxError(n,a)}).finally(()=>{this.setModalButtonsState(!0),this.getModuleContent().querySelectorAll("input").forEach(n=>{n.disabled=!1})})}}var w=new f;export{w as default};
