<?php

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

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

class BookingSettings extends Tag {
	const TAG = 'admin-page-booking-settings';
	const DEFAULT_TEMPLATE = 'bookingSettings';

	/** @var BookingOptions */
	private $bookingOptions;

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

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

		$parser->addContext(OptionGroupArea::OPTION_GROUP_ARRAY_CONTEXT, [$this->bookingOptions]);
		$parser->setData('nonce-name', BookingOptions::INDEX);

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