/*
 * 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!
 */
var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};define(["require","exports","jquery","../AbstractInteractableModule","TYPO3/CMS/Backend/ModuleMenu","TYPO3/CMS/Backend/Notification","TYPO3/CMS/Core/Ajax/AjaxRequest","../../Router","bootstrap","../../Renderable/Clearable"],(function(t,e,a,i,n,r,o,s){"use strict";a=__importDefault(a);class l extends i.AbstractInteractableModule{constructor(){super(...arguments),this.selectorFormListener=".t3js-extensionConfiguration-form",this.selectorSearchInput=".t3js-extensionConfiguration-search"}initialize(t){this.currentModal=t,this.getContent(),t.on("keydown",e=>{const a=t.find(this.selectorSearchInput);e.ctrlKey||e.metaKey?"f"===String.fromCharCode(e.which).toLowerCase()&&(e.preventDefault(),a.trigger("focus")):27===e.keyCode&&(e.preventDefault(),a.val("").trigger("focus"))}),t.on("keyup",this.selectorSearchInput,e=>{const i=(0,a.default)(e.target).val(),n=t.find(this.selectorSearchInput);t.find(".search-item").each((t,e)=>{const n=(0,a.default)(e);(0,a.default)(":contains("+i+")",n).length>0||(0,a.default)('input[value*="'+i+'"]',n).length>0?n.removeClass("hidden").addClass("searchhit"):n.removeClass("searchhit").addClass("hidden")}),t.find(".searchhit").collapse("show");const r=n.get(0);r.clearable(),r.focus()}),t.on("submit",this.selectorFormListener,t=>{t.preventDefault(),this.write((0,a.default)(t.currentTarget))})}getContent(){const t=this.getModalBody();new o(s.getUrl("extensionConfigurationGetContent")).get({cache:"no-cache"}).then(async e=>{const a=await e.resolve();!0===a.success&&(t.html(a.html),this.initializeWrap(),this.initializeColorPicker())},e=>{s.handleAjaxError(e,t)})}initializeColorPicker(){window.location!==window.parent.location?top.require(["TYPO3/CMS/Backend/ColorPicker"],t=>{t.initialize()}):t(["TYPO3/CMS/Backend/ColorPicker"],t=>{t.initialize()})}write(t){const e=this.getModalBody(),i=this.getModuleContent().data("extension-configuration-write-token"),l={};a.default.each(t.serializeArray(),(t,e)=>{l[e.name]=e.value}),new o(s.getUrl()).post({install:{token:i,action:"extensionConfigurationWrite",extensionKey:t.attr("data-extensionKey"),extensionConfiguration:l}}).then(async t=>{const e=await t.resolve();!0===e.success&&Array.isArray(e.status)?(e.status.forEach(t=>{r.showMessage(t.title,t.message,t.severity)}),"backend"===(0,a.default)("body").data("context")&&n.App.refreshMenu()):r.error("Something went wrong","The request was not processed successfully. Please check the browser's console and TYPO3's log.")},t=>{s.handleAjaxError(t,e)})}initializeWrap(){this.findInModal(".t3js-emconf-offset").each((t,e)=>{var i,n;const r=(0,a.default)(e),o=r.parent(),s=r.attr("id"),l=r.attr("value").split(",");r.attr("data-offsetfield-x","#"+s+"_offset_x").attr("data-offsetfield-y","#"+s+"_offset_y").wrap('<div class="hidden"></div>');const d=(0,a.default)("<div>",{class:"form-multigroup-item"}).append((0,a.default)("<div>",{class:"input-group"}).append((0,a.default)("<div>",{class:"input-group-addon"}).text("x"),(0,a.default)("<input>",{id:s+"_offset_x",class:"form-control t3js-emconf-offsetfield","data-target":"#"+s,value:null===(i=l[0])||void 0===i?void 0:i.trim()}))),f=(0,a.default)("<div>",{class:"form-multigroup-item"}).append((0,a.default)("<div>",{class:"input-group"}).append((0,a.default)("<div>",{class:"input-group-addon"}).text("y"),(0,a.default)("<input>",{id:s+"_offset_y",class:"form-control t3js-emconf-offsetfield","data-target":"#"+s,value:null===(n=l[1])||void 0===n?void 0:n.trim()}))),u=(0,a.default)("<div>",{class:"form-multigroup-wrap"}).append(d,f);o.append(u),o.find(".t3js-emconf-offsetfield").on("keyup",t=>{const e=o.find((0,a.default)(t.currentTarget).data("target"));e.val(o.find(e.data("offsetfield-x")).val()+","+o.find(e.data("offsetfield-y")).val())})}),this.findInModal(".t3js-emconf-wrap").each((t,e)=>{var i,n;const r=(0,a.default)(e),o=r.parent(),s=r.attr("id"),l=r.attr("value").split("|");r.attr("data-wrapfield-start","#"+s+"_wrap_start").attr("data-wrapfield-end","#"+s+"_wrap_end").wrap('<div class="hidden"></div>');const d=(0,a.default)("<div>",{class:"form-multigroup-wrap"}).append((0,a.default)("<div>",{class:"form-multigroup-item"}).append((0,a.default)("<input>",{id:s+"_wrap_start",class:"form-control t3js-emconf-wrapfield","data-target":"#"+s,value:null===(i=l[0])||void 0===i?void 0:i.trim()})),(0,a.default)("<div>",{class:"form-multigroup-item"}).append((0,a.default)("<input>",{id:s+"_wrap_end",class:"form-control t3js-emconf-wrapfield","data-target":"#"+s,value:null===(n=l[1])||void 0===n?void 0:n.trim()})));o.append(d),o.find(".t3js-emconf-wrapfield").on("keyup",t=>{const e=o.find((0,a.default)(t.currentTarget).data("target"));e.val(o.find(e.data("wrapfield-start")).val()+"|"+o.find(e.data("wrapfield-end")).val())})})}}return new l}));