/*
 * 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 d from"@typo3/core/document-service.js";import m from"@typo3/backend/ajax-data-handler.js";import u from"@typo3/backend/modal.js";import h from"@typo3/backend/severity.js";import"@typo3/backend/element/icon-element.js";import{SeverityEnum as p}from"@typo3/backend/enum/severity.js";import g from"@typo3/core/event/regular-event.js";import a from"~labels/backend.layout";class l{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,d.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 g("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="'+a.get("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="'+a.get("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=a.get("paste.modal.title.paste")+': "'+this.itemOnClipboardTitle+'"',i=a.get("paste.modal.paste");let s=[];s=[{text:a.get("paste.modal.button.cancel"),active:!0,btnClass:"btn-default",trigger:(n,o)=>o.hideModal()},{text:a.get("paste.modal.button.paste"),btnClass:"btn-"+h.getCssClass(p.warning),trigger:(n,o)=>{o.hideModal(),this.execute(t)}}],u.show(e,i,p.warning,s)}execute(t){const e=l.determineColumn(t),i=t.closest(this.elementIdentifier),s=i.dataset.uid;let n;typeof s>"u"?n=parseInt(i.dataset.page,10):n=0-parseInt(s,10);const o=parseInt(t.closest("[data-language-uid]").dataset.languageUid,10),r={CB:{paste:"tt_content|"+n,pad:"normal",update:{colPos:e,sys_language_uid:o}}};m.process(r).then(c=>{c.hasErrors||window.location.reload()})}}export{l as default};
