/*
 * 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(e){return e&&e.__esModule?e:{default:e}};define(["require","exports","jquery","TYPO3/CMS/Backend/Utility/MessageUtility","./Enum/KeyTypes","nprogress","TYPO3/CMS/Core/Ajax/AjaxRequest","TYPO3/CMS/Core/SecurityUtility","./Modal","./Severity"],(function(e,t,a,i,n,l,r,o,s,d){"use strict";a=__importDefault(a);return new class{constructor(){this.securityUtility=new o,a.default(()=>{this.registerEvents()})}registerEvents(){const e=this;a.default(document).on("click",".t3js-online-media-add-btn",t=>{e.triggerModal(a.default(t.currentTarget))})}addOnlineMedia(e,t){const a=e.data("target-folder"),n=e.data("online-media-allowed"),o=e.data("file-irre-object");l.start(),new r(TYPO3.settings.ajaxUrls.online_media_create).post({url:t,targetFolder:a,allowed:n}).then(async e=>{const t=await e.resolve();if(t.file){const e={actionName:"typo3:foreignRelation:insert",objectGroup:o,table:"sys_file",uid:t.file};i.MessageUtility.send(e)}else{const e=s.confirm("ERROR",t.error,d.error,[{text:TYPO3.lang["button.ok"]||"OK",btnClass:"btn-"+d.getCssClass(d.error),name:"ok",active:!0}]).on("confirm.button.ok",()=>{e.modal("hide")})}l.done()})}triggerModal(e){const t=e.data("btn-submit")||"Add",i=e.data("placeholder")||"Paste media url here...",l=a.default.map(e.data("online-media-allowed").split(","),e=>'<span class="label label-success">'+this.securityUtility.encodeHtml(e.toUpperCase(),!1)+"</span>"),r=e.data("online-media-allowed-help-text")||"Allow to embed from sources:",o=a.default("<div>").attr("class","form-control-wrap").append([a.default("<input>").attr("type","text").attr("class","form-control online-media-url").attr("placeholder",i),a.default("<div>").attr("class","help-block").html(this.securityUtility.encodeHtml(r,!1)+"<br>"+l.join(" "))]),c=s.show(e.attr("title"),o,d.notice,[{text:t,btnClass:"btn btn-primary",name:"ok",trigger:()=>{const t=c.find("input.online-media-url").val();t&&(c.modal("hide"),this.addOnlineMedia(e,t))}}]);c.on("shown.bs.modal",e=>{a.default(e.currentTarget).find("input.online-media-url").first().focus().on("keydown",e=>{e.keyCode===n.KeyTypesEnum.ENTER&&c.find('button[name="ok"]').trigger("click")})})}}}));