<?php

namespace Planaday\Html\NodeTags\Testing\NodeControlTest;

use DOMNode;
use Planaday\Html\NodeTags\InnerContentControl;
use Planaday\Html\NodeTags\Tag;
use Planaday\Html\NodeTags\TagCore;
use Planaday\Html\NodeTags\TagNotFullyInitializedException;
use Planaday\Html\Nodes\NodeData;
use Planaday\Html\Nodes\ParserNode;
use Planaday\Utility\DependencyInjection\Attributes\Transient;

#[Transient]
class NodeControlTest implements Tag {
	use TagCore;
	use InnerContentControl;


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

		$nodeData = $this->nodeData ?? new NodeData();
		$nodeData->data["test"] = ["data" => "Successful"];
		$nodeData->data["testArray"] = [
			"Successful 1",
			"Successful 2"
		];
		$nodeData->data["tableData"] = [
			1 => [1 => "dieper 1", 2 => "dieper 2"],
			3 => "test data 2",
			"also string key" => "test data 3"
		];
		$nodeData->data["ifValue"] = true;
		$nodeData->data["ifValue2"] = false;
		$nodeData->data["ifValue3"] = 3;
		$nodeData->data["ifValue4"] = 3;

		$nodeData->data["testXml"] = "<span style='color: green'>successful if green</span>";

		$newNode = $this->originalNode->getNodeFromTemplate($this->getTemplate());


		$this->logDebug("placing inner content.");

		$innerContent = $this->getInnerContentFragment($this->originalNode);
		$innerContent->setExtendedNodeData( $nodeData );
		$this->replaceContentTagWithinFragment("pad-content", $innerContent, $newNode);

		return $newNode;
	}

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