<?php

namespace Planaday\Html\NodeTags;

use DOMNode;
use Planaday\Html\Nodes\NodeCouldNotBeCreatedException;
use Planaday\Html\Nodes\NodeData;
use Planaday\Html\Nodes\ParserNode;

trait TemplateOnlyTag {
	use TagCore;

	/**
	 * @throws TagNotFullyInitializedException
	 * @throws NodeCouldNotBeCreatedException
	 */
	public function getNewNode(): DOMNode&ParserNode {
		if ( !isset( $this->originalNode ) ){
			throw new TagNotFullyInitializedException("The PreParser or the OriginalNode is not set");
		}

		$this->logDebug("TemplateOnlyTag: passing through");

		$nodeData = $this->nodeData ?? new NodeData();

		$this->prepareData($nodeData);

		$node = $this->originalNode->getNodeFromTemplate($this->getTemplate());
		$node->setExtendedNodeData( $nodeData );
		return $node;
	}

	protected function prepareData(NodeData $nodeData): void {}
}