<?php

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

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

class CourseSettings extends Tag {
	const TAG = 'admin-page-course-settings';
	const DEFAULT_TEMPLATE = 'courseSettings';

	/** @var CourseOptions */
	private $courseSettings;

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

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