/*
 * 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 a}from"lit";import{DataTransferTypes as i}from"@typo3/backend/enum/data-transfer-types.js";import n 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";import p from"@typo3/core/ajax/ajax-request.js";class m 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}ensureActiveNodeLoaded(e){return!e||this.nodes.find(t=>t.checked)?Promise.resolve():new p(TYPO3.settings.ajaxUrls.page_tree_rootline).withQueryArguments({identifier:e}).get({cache:"no-cache"}).then(t=>t.resolve()).then(t=>{const{rootline:r}=t;return r.pop(),this.expandParents(r)})}createNodeToggle(e){return a`${e.stopPageTree&&e.depth!==0?a`<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(i.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(i.content)){const t=this.getNodeFromDragEvent(e);if(t===null)return!1;const r=e.dataTransfer.getData(i.content),d=JSON.parse(r);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"),n.advanced({content:o.toString(),severity:u.notice,size:n.sizes.large,type:n.types.iframe}),!0}return!1}}export{m as PageTree};
