<?php

namespace Planaday\Html\NodeTags\Core\XmlFragmentTag;

use DOMNode;
use Planaday\Html\Nodes\ParserNode;
use Planaday\Html\NodeTags\InnerContentControl;
use Planaday\Html\NodeTags\Tag;
use Planaday\Html\NodeTags\TagCore;
use Planaday\Html\NodeTags\TagNotFullyInitializedException;

class XmlFragmentTag implements Tag {
	use TagCore;
	use InnerContentControl;

	public function getNewNode(): DOMNode&ParserNode {
		if ( !isset( $this->originalNode ) ){
			throw new TagNotFullyInitializedException("The OriginalNode is not set");
		}

		$outputFragment = $this->originalNode->getUsableDocumentFragment();

		$inputXml = $this->attributes["xml"] ?? null;
		$this->logDebug("inputXml is: " . $inputXml);

		if (! is_string($inputXml)) {
			return $outputFragment;
		}

		return $this->originalNode->getNodeFromTemplate( $inputXml );
	}

	public function getTagDir(): string {
		return '';
	}
}