<?php

namespace Planaday\Html\Tags\Generic;

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

class GenericStyleTag extends Tag {
	const TAG = 'style';
	const DEFAULT_TEMPLATE = '';
	const STYLE_ATTRIBUTE = self::ATTRIBUTE_PREFIX . 'style';

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

	public function buildTag(): string {
		$parser = $this->getNewParser();
		$selectedStyle = $this->attributes[self::STYLE_ATTRIBUTE] ?? null;
		if (is_string($selectedStyle)){
			$parser->addStylesheet($this->getStylePath($selectedStyle));
		}
		return $parser->parse('');
	}
}