<?php

namespace Planaday\Html\Tags\Platform\NonceCheckTag;

use Planaday\Html\Tags\Tag;
use Planaday\Platform\PlatformAbstraction\HtmlService;
use Planaday\Utility\DependencyInjection\Container;
use Planaday\Utility\DependencyInjection\InjectionImpossibleException;

class NonceCheckTag extends Tag {
	const TAG = 'platform-nonce-check';
	const DEFAULT_TEMPLATE = '';
	const NONCE_CHECK_NAME_ATTRIBUTE = 'data-check-name';

	protected HtmlService $htmlService;

	/**
	 * @param Container $registry
	 *
	 * @throws InjectionImpossibleException
	 */
	public function __construct(Container $registry) {
		$this->htmlService = $registry->getInstance(HtmlService::class);
		parent::__construct(__DIR__, self::DEFAULT_TEMPLATE, $registry);
	}

	public function buildTag(): string {
		$parser = $this->getNewParser();
		return $parser->parse( $this->htmlService->getNonceCheckField( $this->attributes[self::NONCE_CHECK_NAME_ATTRIBUTE] ?? '' ));
	}
}