<?php

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

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

class Payment extends Tag {
	const TAG = 'admin-page-payment';
	const DEFAULT_TEMPLATE = 'payment';

	/** @var PaymentOptions */
	private $paymentOptions;

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

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