/*
 * 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 i from"nprogress";import r from"@typo3/backend/modal.js";import a from"@typo3/backend/notification.js";import c from"@typo3/backend/severity.js";import g from"@typo3/backend/sortable-table.js";import"@typo3/backend/input/clearable.js";import m from"@typo3/core/ajax/ajax-request.js";import p from"@typo3/core/event/regular-event.js";class f{constructor(){this.getDependencies=async t=>{const e=await t.resolve(),n=document.createElement("div");n.innerHTML=e.message,i.done(),e.hasDependencies?r.confirm(e.title,n,c.info,[{text:TYPO3.lang["button.cancel"],active:!0,btnClass:"btn-default",trigger:()=>{r.dismiss()}},{text:TYPO3.lang["button.resolveDependencies"],btnClass:"btn-primary",trigger:()=>{this.getResolveDependenciesAndInstallResult(e.url),r.dismiss()}}]):e.hasErrors?a.error(e.title,e.message,15):this.getResolveDependenciesAndInstallResult(e.url)}}initDom(){i.configure({parent:".module-loading-indicator",showSpinner:!1});const t=document.getElementById("terVersionTable"),e=document.getElementById("terSearchTable");t instanceof HTMLTableElement&&new g(t),e instanceof HTMLTableElement&&new g(e),this.bindDownload(),this.bindSearchFieldResetter()}bindDownload(){new p("click",(t,e)=>{t.preventDefault();const l=e.closest("form").dataset.href;i.start(),new m(l).get().then(this.getDependencies)}).delegateTo(document,".downloadFromTer form.download button[type=submit]")}getResolveDependenciesAndInstallResult(t){i.start(),new m(t).post({}).then(async e=>{try{const n=await e.raw().json(),l=document.createElement("div");if(l.innerHTML=n.errorMessage,n.errorCount>0){const s=r.confirm(n.errorTitle,l,c.error,[{text:TYPO3.lang["button.cancel"],active:!0,btnClass:"btn-default",trigger:()=>{r.dismiss()}},{text:TYPO3.lang["button.resolveDependenciesIgnore"],btnClass:"btn-danger disabled t3js-dependencies",trigger:o=>{o.currentTarget.classList.contains("disabled")||(this.getResolveDependenciesAndInstallResult(n.skipDependencyUri),r.dismiss())}}]);s.addEventListener("typo3-modal-shown",()=>{const o=s.querySelector(".t3js-dependencies");s.querySelector('input[name="unlockDependencyIgnoreButton"]').addEventListener("change",d=>{d.currentTarget.checked?o?.classList.remove("disabled"):o?.classList.add("disabled")})})}else{let s=TYPO3.lang["extensionList.dependenciesResolveDownloadSuccess.message"+n.installationTypeLanguageKey].replace(/\{0\}/g,n.extension);s+=`
`+TYPO3.lang["extensionList.dependenciesResolveDownloadSuccess.header"]+": ";for(const[o,d]of Object.entries(n.result)){s+=`

`+TYPO3.lang["extensionList.dependenciesResolveDownloadSuccess.item"]+" "+o+": ";for(const u of Object.keys(d))s+=`
* `+u}a.info(TYPO3.lang["extensionList.dependenciesResolveFlashMessage.title"+n.installationTypeLanguageKey].replace(/\{0\}/g,n.extension),s,15),top.TYPO3.ModuleMenu.App.refreshMenu()}}catch{a.error(TYPO3.lang["extensionList.dependenciesResolveInstallError.title"]||"Install error",TYPO3.lang["extensionList.dependenciesResolveInstallError.message"]||"Your installation failed while resolving dependencies.")}},()=>{a.error(TYPO3.lang["extensionList.dependenciesResolveInstallError.title"]||"Install error",TYPO3.lang["extensionList.dependenciesResolveInstallError.message"]||"Your installation failed while resolving dependencies.")}).finally(()=>{i.done()})}bindSearchFieldResetter(){let t;if((t=document.querySelector('.typo3-extensionmanager-searchTerForm input[type="text"]'))!==null){const e=t.value!=="";t.clearable({onClear:n=>{e&&n.closest("form").submit()}})}}}export{f as default};
