<?php

namespace Planaday\Html\Tags\Admin\Pages\GeneralSettings;

use Planaday\Config\OptionGroups\General\GeneralOptions;
use Planaday\Html\Tags\Admin\Form\OptionGroupArea\OptionGroupArea;
use Planaday\Html\Tags\Tag;
use Planaday\Utility\DependencyInjection\ComponentRegistry;
use Planaday\Utility\DependencyInjection\InjectionImpossibleException;

class GeneralSettings extends Tag {
	const TAG = 'admin-page-general-settings';
	const DEFAULT_TEMPLATE = 'generalSettings';

	/** @var GeneralOptions */
	private $generalOptions;

	/**
	 * @param ComponentRegistry $registry
	 *
	 * @throws InjectionImpossibleException
	 */
	public function __construct(ComponentRegistry $registry) {
		$this->generalOptions = $registry->getComponent(GeneralOptions::class);
		parent::__construct(__DIR__, self::DEFAULT_TEMPLATE, $registry);
	}

	public function buildTag(): string {
		$parser = $this->getNewParser();
		$parser->addContext(OptionGroupArea::OPTION_GROUP_ARRAY_CONTEXT, [$this->generalOptions]);
		$parser->setData('nonce-name', GeneralOptions::INDEX);
		return $parser->parse($this->getTemplate());
	}
}