<?php

namespace Planaday\Html\Tags;

use Planaday\Utility\DependencyInjection\Container;

abstract class TagHandlerTemplate {
	/** @var array<callable(Container):Tag> */
	protected array $tags;

	/** @var null|TagHandlerTemplate[] */
	protected ?array $tagHandlers;

	/**
	 * @param array<callable(Container):Tag> $tagRegister
	 *
	 * @return array<callable(Container):Tag>
	 */
	public function registerTags(array $tagRegister):array {
		foreach ($this->tags as $tagKey => $tag){
			if (array_key_exists($tagKey, $tagRegister)){
				continue;
			}

			$tagRegister[$tagKey] = $tag;
		}

		if (isset($this->tagHandlers) && count($this->tagHandlers) > 0){
			foreach ($this->tagHandlers as $tagHandler){
				$tagRegister = $tagHandler->registerTags($tagRegister);
			}
		}

		return $tagRegister;
	}
}