/*
 * 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","../AjaxDataHandler","../Modal","../Severity","../Enum/Severity","TYPO3/CMS/Backend/Element/IconElement"],(function(t,e,a,n,s,i,o){"use strict";a=__importDefault(a);class l{constructor(){this.itemOnClipboardUid=0,this.itemOnClipboardTitle="",this.copyMode="",this.elementIdentifier=".t3js-page-ce",this.pasteAfterLinkTemplate="",this.pasteIntoLinkTemplate="",a.default(()=>{a.default(".t3js-page-columns").length&&(this.generateButtonTemplates(),this.activatePasteIcons(),this.initializeEvents())})}static determineColumn(t){const e=t.closest("[data-colpos]");return e.length&&"undefined"!==e.data("colpos")?e.data("colpos"):0}initializeEvents(){a.default(document).on("click",".t3js-paste",t=>{t.preventDefault(),this.activatePasteModal(a.default(t.currentTarget))})}generateButtonTemplates(){var t,e;this.itemOnClipboardUid&&(this.pasteAfterLinkTemplate='<button type="button" class="t3js-paste t3js-paste'+(this.copyMode?"-"+this.copyMode:"")+' t3js-paste-after btn btn-default btn-sm" title="'+(null===(t=TYPO3.lang)||void 0===t?void 0:t.pasteAfterRecord)+'"><typo3-backend-icon identifier="actions-document-paste-into" size="small"></typo3-backend-icon></button>',this.pasteIntoLinkTemplate='<button type="button" class="t3js-paste t3js-paste'+(this.copyMode?"-"+this.copyMode:"")+' t3js-paste-into btn btn-default btn-sm" title="'+(null===(e=TYPO3.lang)||void 0===e?void 0:e.pasteIntoColumn)+'"><typo3-backend-icon identifier="actions-document-paste-into" size="small"></typo3-backend-icon></button>')}activatePasteIcons(){a.default(".t3-page-ce-wrapper-new-ce").each((t,e)=>{if(this.pasteAfterLinkTemplate&&this.pasteIntoLinkTemplate){a.default(e).parent().data("page")?a.default(e).append(this.pasteIntoLinkTemplate):a.default(e).append(this.pasteAfterLinkTemplate)}})}activatePasteModal(t){const e=(TYPO3.lang["paste.modal.title.paste"]||"Paste record")+': "'+this.itemOnClipboardTitle+'"',a=TYPO3.lang["paste.modal.paste"]||"Do you want to paste the record to this position?";let n=[];n=[{text:TYPO3.lang["paste.modal.button.cancel"]||"Cancel",active:!0,btnClass:"btn-default",trigger:()=>{s.currentModal.trigger("modal-dismiss")}},{text:TYPO3.lang["paste.modal.button.paste"]||"Paste",btnClass:"btn-"+i.getCssClass(o.SeverityEnum.warning),trigger:()=>{s.currentModal.trigger("modal-dismiss"),this.execute(t)}}],s.show(e,a,o.SeverityEnum.warning,n)}execute(t){const e=l.determineColumn(t),a=t.closest(this.elementIdentifier),s=a.data("uid");let i;i=void 0===s?parseInt(a.data("page"),10):0-parseInt(s,10);const o={CB:{paste:"tt_content|"+i,pad:"normal",update:{colPos:e,sys_language_uid:parseInt(t.closest("[data-language-uid]").data("language-uid"),10)}}};n.process(o).then(t=>{t.hasErrors||window.location.reload()})}}return new l}));