<?php

namespace Planaday\Html\Tags\Platform\EditorTag;

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

class EditorTag extends Tag {
	const TAG = 'platform-editor';
	const DEFAULT_TEMPLATE = '';
	const FIELD_VALUE_ATTRIBUTE = 'data-field-value';

	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->getAdminTextArea($this->attributes[self::FIELD_VALUE_ATTRIBUTE] ?? null, $parser->getParserUniqueId(), $this->attributes ));
	}
}