<?php

namespace Planaday\Html\Tags\Generic;

use Planaday\Html\Tags\Tag;
use Planaday\Utility\DependencyInjection\Container;
use Planaday\Utility\DependencyInjection\InjectionImpossibleException;

class GenericScriptTag extends Tag {
	const TAG = 'script';
	const DEFAULT_TEMPLATE = '';
	const SCRIPT_ATTRIBUTE = self::ATTRIBUTE_PREFIX . 'script';

	/**
	 * @param Container $registry
	 *
	 * @throws InjectionImpossibleException
	 */
	public function __construct(Container $registry) {
		parent::__construct(__DIR__, self::DEFAULT_TEMPLATE, $registry);
	}

	public function buildTag(): string {
		$parser = $this->getNewParser();
		$selectedScript = $this->attributes[self::SCRIPT_ATTRIBUTE] ?? null;
		if (is_string($selectedScript)){
			$parser->addScript($this->getScriptPath($selectedScript));
		}
		return $parser->parse('');
	}
}