<?php

namespace Planaday\Html\Tags\Form\GenericInput\ActionButton;

use Planaday\Entities\PostEntities;
use Planaday\Html\Tags\Tag;
use Planaday\Utility\DependencyInjection\Container;
use Planaday\Utility\DependencyInjection\InjectionImpossibleException;
use Planaday\Utility\PluginData;

class ActionButton extends Tag {
	const TAG = 'action-button';
	const DEFAULT_TEMPLATE = 'actionButton';
	const ACTION_ATTRIBUTE = self::ATTRIBUTE_PREFIX . 'action';

	private PluginData $pluginData;

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

	public function buildTag(): string {
		$parser = $this->getNewParser();

		$action = $this->attributes[self::ACTION_ATTRIBUTE] ?? '';
		$name = $this->pluginData->getFullPrefix() . PostEntities::POST_ACTION . '[]';

		$parser->setData('action', $action);
		$parser->setData('name', $name);

		return $parser->parse($this->getTemplate());
	}
}