/*
 * 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 c from"@typo3/core/document-service.js";import d from"@typo3/backend/ajax-data-handler.js";import m from"@typo3/backend/modal.js";import u from"@typo3/backend/severity.js";import"@typo3/backend/element/icon-element.js";import{SeverityEnum as l}from"@typo3/backend/enum/severity.js";import h from"@typo3/core/event/regular-event.js";class i{constructor(t){this.itemOnClipboardUid=0,this.itemOnClipboardTitle="",this.copyMode="",this.elementIdentifier=".t3js-page-ce",this.pasteAfterLinkTemplate="",this.pasteIntoLinkTemplate="",this.itemOnClipboardUid=t.itemOnClipboardUid,this.itemOnClipboardTitle=t.itemOnClipboardTitle,this.copyMode=t.copyMode,c.ready().then(()=>{document.querySelectorAll(".t3js-page-columns").length>0&&(this.generateButtonTemplates(),this.activatePasteIcons(),this.initializeEvents())})}static determineColumn(t){const e=t.closest("[data-colpos]");return parseInt(e?.dataset?.colpos??"0",10)}initializeEvents(){new h("click",(t,e)=>{t.preventDefault(),this.activatePasteModal(e)}).delegateTo(document,".t3js-paste")}generateButtonTemplates(){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="'+TYPO3.lang?.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="'+TYPO3.lang?.pasteIntoColumn+'"><typo3-backend-icon identifier="actions-document-paste-into" size="small"></typo3-backend-icon></button>')}activatePasteIcons(){this.pasteAfterLinkTemplate&&this.pasteIntoLinkTemplate&&document.querySelectorAll(".t3js-page-new-ce").forEach(t=>{const e=t.parentElement.dataset.page?this.pasteIntoLinkTemplate:this.pasteAfterLinkTemplate;t.append(document.createRange().createContextualFragment(e))})}activatePasteModal(t){const e=(TYPO3.lang["paste.modal.title.paste"]||"Paste record")+': "'+this.itemOnClipboardTitle+'"',o=TYPO3.lang["paste.modal.paste"]||"Do you want to paste the record to this position?";let a=[];a=[{text:TYPO3.lang["paste.modal.button.cancel"]||"Cancel",active:!0,btnClass:"btn-default",trigger:(n,s)=>s.hideModal()},{text:TYPO3.lang["paste.modal.button.paste"]||"Paste",btnClass:"btn-"+u.getCssClass(l.warning),trigger:(n,s)=>{s.hideModal(),this.execute(t)}}],m.show(e,o,l.warning,a)}execute(t){const e=i.determineColumn(t),o=t.closest(this.elementIdentifier),a=o.dataset.uid;let n;typeof a>"u"?n=parseInt(o.dataset.page,10):n=0-parseInt(a,10);const s=parseInt(t.closest("[data-language-uid]").dataset.languageUid,10),p={CB:{paste:"tt_content|"+n,pad:"normal",update:{colPos:e,sys_language_uid:s}}};d.process(p).then(r=>{r.hasErrors||window.location.reload()})}}export{i as default};
