/*
 * 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{Collapse as h}from"bootstrap";import"@typo3/install/renderable/wrap-group.js";import"@typo3/install/renderable/offset-group.js";import{AbstractInteractableModule as w}from"@typo3/install/module/abstract-interactable-module.js";import g from"@typo3/backend/module-menu.js";import u from"@typo3/backend/notification.js";import p from"@typo3/core/ajax/ajax-request.js";import l from"@typo3/install/router.js";import{topLevelModuleImport as f}from"@typo3/backend/utility/top-level-module-import.js";import c from"@typo3/core/event/regular-event.js";import y from"@typo3/core/event/debounce-event.js";var n;(function(d){d.formListener=".t3js-extensionConfiguration-form",d.searchInput=".t3js-extensionConfiguration-search"})(n||(n={}));class m extends w{initialize(o){super.initialize(o),this.getContent(),new c("keydown",e=>{const t=o.querySelector(n.searchInput);(e.ctrlKey||e.metaKey)&&(e.key==="f"||e.key==="F")&&(e.preventDefault(),t.focus())}).bindTo(o),new y("input",(e,t)=>{const a=t.value;this.search(a)},100).delegateTo(o,n.searchInput),new c("change",(e,t)=>{const a=t.value;this.search(a)}).delegateTo(o,n.searchInput),new c("submit",(e,t)=>{e.preventDefault(),this.write(t)}).delegateTo(o,n.formListener)}search(o){this.currentModal.querySelectorAll(".search-item").forEach(e=>{o===""||e.textContent.toLowerCase().trim().includes(o.toLowerCase())?(e.classList.add("searchhit"),e.classList.remove("hidden")):(e.classList.remove("searchhit"),e.classList.add("hidden"))}),this.currentModal.querySelectorAll(".searchhit").forEach(e=>{h.getOrCreateInstance(e).show()})}getContent(){const o=this.getModalBody();new p(l.getUrl("extensionConfigurationGetContent")).get({cache:"no-cache"}).then(async e=>{const t=await e.resolve();t.success===!0&&(o.innerHTML=t.html,this.initializeWrap(),this.initializeColorPicker())},e=>{l.handleAjaxError(e,o)})}initializeColorPicker(){window.location!==window.parent.location?f("@typo3/backend/color-picker.js"):import("@typo3/backend/color-picker.js")}write(o){const e=this.getModalBody(),t=this.getModuleContent().dataset.extensionConfigurationWriteToken,a={};for(const[i,s]of new FormData(o))a[i]=s.toString();new p(l.getUrl()).post({install:{token:t,action:"extensionConfigurationWrite",extensionKey:o.dataset.extensionKey,extensionConfiguration:a}}).then(async i=>{const s=await i.resolve();s.success===!0&&Array.isArray(s.status)?(s.status.forEach(r=>{u.showMessage(r.title,r.message,r.severity)}),document.body.dataset.context==="backend"&&g.App.refreshMenu()):u.error("Something went wrong","The request was not processed successfully. Please check the browser's console and TYPO3's log.")},i=>{l.handleAjaxError(i,e)})}initializeWrap(){window.location!==window.parent.location&&(f("@typo3/install/renderable/wrap-group.js"),f("@typo3/install/renderable/offset-group.js")),this.currentModal.querySelectorAll(".t3js-emconf-offset").forEach(e=>{const t=e.parentElement;e.setAttribute("data-offsetfield-x","#"+e.id+"_offset_x"),e.setAttribute("data-offsetfield-y","#"+e.id+"_offset_y"),e.classList.add("hidden");const a=t.ownerDocument.createElement("typo3-install-offset-group");a.offsetId=e.id,a.values=e.value.split(","),t.appendChild(a),new c("keyup",(i,s)=>{const r=t.querySelector(s.dataset.target);r.value=t.querySelector(r.dataset.offsetfieldX).value+","+t.querySelector(r.dataset.offsetfieldY).value}).delegateTo(t,".t3js-emconf-offsetfield")}),this.currentModal.querySelectorAll(".t3js-emconf-wrap").forEach(e=>{const t=e.parentElement;e.setAttribute("data-wrapfield-start","#"+e.id+"_wrap_start"),e.setAttribute("data-wrapfield-end","#"+e.id+"_wrap_end"),e.classList.add("hidden");const a=t.ownerDocument.createElement("typo3-install-wrap-group");a.wrapId=e.id,a.values=e.value.split("|"),t.appendChild(a),new c("keyup",(i,s)=>{const r=t.querySelector(s.dataset.target);r.value=t.querySelector(r.dataset.wrapfieldStart).value+"|"+t.querySelector(r.dataset.wrapfieldEnd).value}).delegateTo(t,".t3js-emconf-wrapfield")})}}var v=new m;export{v as default};
