/*
 * 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 w from"@typo3/core/document-service.js";import x from"@typo3/backend/storage/browser-session.js";import s from"nprogress";import a from"@typo3/backend/modal.js";import b from"@typo3/backend/severity.js";import C from"@typo3/core/security-utility.js";import O from"@typo3/extensionmanager/repository.js";import M from"@typo3/extensionmanager/update.js";import P from"@typo3/extensionmanager/upload-form.js";import"@typo3/backend/input/clearable.js";import p from"@typo3/core/ajax/ajax-request.js";import S from"@typo3/core/event/debounce-event.js";import l from"@typo3/core/event/regular-event.js";import k from"@typo3/backend/sortable-table.js";const E=new C;var f;(function(g){g.extensionlist="typo3-extension-list",g.searchField="#Tx_Extensionmanager_extensionkey"})(f||(f={}));class Y{constructor(){this.searchFilterSessionKey="tx-extensionmanager-local-filter",w.ready().then(()=>{this.Update=new M,this.UploadForm=new P,this.Repository=new O;const o=document.getElementById(f.extensionlist);o!==null&&(o instanceof HTMLTableElement&&new k(o),new l("click",(e,t)=>{e.preventDefault(),a.confirm(TYPO3.lang["extensionList.removalConfirmation.title"],TYPO3.lang["extensionList.removalConfirmation.question"],b.error,[{text:TYPO3.lang["button.cancel"],active:!0,btnClass:"btn-default",trigger:()=>{a.dismiss()}},{text:TYPO3.lang["button.remove"],btnClass:"btn-danger",trigger:()=>{this.removeExtensionFromDisk(t),a.dismiss()}}])}).delegateTo(o,".removeExtension"),new l("click",(e,t)=>{e.preventDefault(),a.confirm(TYPO3.lang["extensionList.databaseReload.title"],TYPO3.lang["extensionList.databaseReload.message"],b.warning,[{text:TYPO3.lang["button.cancel"],active:!0,btnClass:"btn-default",trigger:()=>{a.dismiss()}},{text:TYPO3.lang["button.reimport"],btnClass:"btn-warning",trigger:()=>{s.start(),new p(t.href).post({}).then(()=>{location.reload()}).finally(()=>{s.done(),a.dismiss()})}}])}).delegateTo(o,".reloadSqlData")),new l("click",()=>{s.start()}).delegateTo(document,".onClickMaskExtensionManager"),new l("click",(e,t)=>{e.preventDefault(),s.start(),new p(t.href).get().then(this.updateExtension)}).delegateTo(document,"a[data-action=update-extension]"),new l("change",(e,t)=>{const n=document.querySelector(".t3js-dependencies");t.checked?n.classList.remove("disabled"):n.classList.add("disabled")}).delegateTo(document,"input[name=unlockDependencyIgnoreButton]"),new l("click",()=>{s.start()}).delegateTo(document,".t3-button-action-installdistribution");let i;if((i=document.querySelector(f.searchField))!==null){const e=x.get(this.searchFilterSessionKey);e!==null&&(i.value=e,this.filterExtensions(e)),new l("submit",t=>{t.preventDefault()}).bindTo(i.closest("form")),new S("input",t=>{const n=t.target;x.set(this.searchFilterSessionKey,n.value),this.filterExtensions(n.value)},100).bindTo(i),i.clearable({onClear:()=>{x.unset(this.searchFilterSessionKey),this.filterExtensions("")}})}this.Repository.initDom(),this.Update.initializeEvents(),this.UploadForm.initializeEvents()})}filterExtensions(o){const i=document.querySelectorAll("[data-filterable]"),e=[];i.forEach(n=>{const c=Array.from(n.parentElement.children);e.push(c.indexOf(n))}),document.querySelectorAll("#typo3-extension-list tbody tr").forEach(n=>{const c=e.map(r=>n.children.item(r)),d=[];c.forEach(r=>{d.push(r.textContent.trim().replace(/\s+/g," "))}),n.classList.toggle("hidden",o!==""&&!RegExp(o,"i").test(d.join(":")))})}removeExtensionFromDisk(o){s.start(),new p(o.href).post({}).then(()=>{location.reload()}).finally(()=>{s.done()})}async updateExtension(o){let i=0;const e=await o.resolve(),t=document.createElement("form");for(const[r,m]of Object.entries(e.updateComments)){const u=document.createElement("input");u.setAttribute("type","radio"),u.setAttribute("name","version"),u.value=r,i===0&&u.setAttribute("checked","checked");const h=document.createElement("h3");h.innerHTML=E.encodeHtml(r),h.prepend(u);const v=document.createElement("div");v.innerHTML=m.replace(/(\r\n|\n\r|\r|\n)/g,`
`).split(/\n/).map(T=>E.encodeHtml(T)).join("<br>"),t.append(h,v),i++}const n=document.createElement("h1");n.textContent=TYPO3.lang["extensionList.updateConfirmation.title"];const c=document.createElement("h2");c.textContent=TYPO3.lang["extensionList.updateConfirmation.message"];const d=document.createElement("div");d.append(n,c,t),s.done(),a.confirm(TYPO3.lang["extensionList.updateConfirmation.questionVersionComments"],d,b.warning,[{text:TYPO3.lang["button.cancel"],active:!0,btnClass:"btn-default",trigger:(r,m)=>m.hideModal()},{text:TYPO3.lang["button.updateExtension"],btnClass:"btn-warning",trigger:(r,m)=>{s.start(),new p(e.url).post({version:m.querySelector('input[name="version"]:checked')?.value}).finally(()=>{location.reload()}),m.hideModal()}}])}}const y=new Y;typeof TYPO3.ExtensionManager>"u"&&(TYPO3.ExtensionManager=y);export{y as default};
