<?php

namespace Planaday\Html\Tags\Course\Dates;

use Planaday\Html\Tags\DayParts\DayPartItem\DayPartItem;
use Planaday\Html\Tags\DayParts\DayPartList\DayPartList;
use Planaday\Html\Tags\Tag;
use Planaday\Utility\DependencyInjection\Container;
use Planaday\Utility\DependencyInjection\InjectionImpossibleException;

class CourseDates extends Tag {
	const TAG = 'legacy-course-dates';

	const DEFAULT_TEMPLATE = '';
	const ID_ATTRIBUTE = 'data-id';
	const SHOW_LOCATION_ATTRIBUTE = 'data-show-location';

	/**
	 * @param Container $registry
	 *
	 * @throws InjectionImpossibleException
	 */
	public function __construct( Container $registry ) {
		parent::__construct( __DIR__, self::DEFAULT_TEMPLATE, $registry );
	}

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

		$html = Tag::getParsableTag(
			DayPartList::TAG,
			[
				DayPartList::ID_ATTRIBUTE                                                     => $this->attributes[ self::ID_ATTRIBUTE ] ?? null,
				DayPartList::INCLUDE_E_LEARNING_DAY_PARTS_ATTRIBUTE                           => "1",
				Tag::TEMPLATE_ATTRIBUTE                                                       => "dayPartListNoTitle",
				$this->getRecursiveVersionOfAttribute( DayPartItem::SHOW_LOCATION_ATTRIBUTE ) => $this->attributes[ self::SHOW_LOCATION_ATTRIBUTE ] ?? null
			]
		);

		return $parser->parse( $html );
	}
}