/*
 * 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{Tree as l}from"@typo3/backend/tree/tree.js";import{html as n}from"lit";import{DataTransferTypes as r}from"@typo3/backend/enum/data-transfer-types.js";import i from"@typo3/backend/modal.js";import{SeverityEnum as u}from"@typo3/backend/enum/severity.js";import s from"@typo3/backend/utility/drag-drop-utility.js";class p extends l{constructor(){super(),this.settings.defaultProperties={hasChildren:!1,nameSourceField:"title",prefix:"",suffix:"",locked:!1,loaded:!1,overlayIcon:"",selectable:!0,expanded:!1,checked:!1,stopPageTree:!1}}getDataUrl(e=null){return e===null?this.settings.dataUrl:this.settings.dataUrl+"&parent="+e.identifier+"&mount="+e.mountPoint+"&depth="+e.depth}createNodeToggle(e){return n`${e.stopPageTree&&e.depth!==0?n`<span class=node-stop @click=${t=>{t.preventDefault(),t.stopImmediatePropagation(),document.dispatchEvent(new CustomEvent("typo3:pagetree:mountPoint",{detail:{pageId:parseInt(e.identifier,10)}}))}}> <typo3-backend-icon identifier=actions-caret-end size=small></typo3-backend-icon> </span>`:super.createNodeToggle(e)}`}handleNodeDragOver(e){if(super.handleNodeDragOver(e))return!0;if(e.dataTransfer.types.includes(r.content)){const t=this.getNodeFromDragEvent(e);return t===null?!1:(this.cleanDrag(),this.getElementFromNode(t).classList.add("node-hover"),t.hasChildren&&!t.__expanded?this.openNodeTimeout.targetNode!=t&&(this.openNodeTimeout.targetNode=t,clearTimeout(this.openNodeTimeout.timeout),this.openNodeTimeout.timeout=setTimeout(()=>{this.showChildren(this.openNodeTimeout.targetNode),this.openNodeTimeout.targetNode=null,this.openNodeTimeout.timeout=null},1e3)):(clearTimeout(this.openNodeTimeout.timeout),this.openNodeTimeout.targetNode=null,this.openNodeTimeout.timeout=null),e.preventDefault(),s.updateEventAndTooltipToReflectCopyMoveIntention(e),!0)}return!1}handleNodeDrop(e){if(super.handleNodeDrop(e))return!0;if(e.dataTransfer.types.includes(r.content)){const t=this.getNodeFromDragEvent(e);if(t===null)return!1;const a=e.dataTransfer.getData(r.content),d=JSON.parse(a);e.preventDefault();const o=new URL(d.moveElementUrl,window.origin);return o.searchParams.set("expandPage",t.identifier),o.searchParams.set("originalPid",t.identifier),s.isCopyModifierFromEvent(e)&&o.searchParams.set("makeCopy","1"),i.advanced({content:o.toString(),severity:u.notice,size:i.sizes.large,type:i.types.iframe}),!0}return!1}}export{p as PageTree};
