<?php

namespace Planaday\Html\Tags\Course\CourseSearchShortcode;

use Planaday\Config\Course\Search\SearchSettings;
use Planaday\Html\Tags\Tag;
use Planaday\Utility\DependencyInjection\Container;
use Planaday\Utility\DependencyInjection\InjectionImpossibleException;

class CourseSearchShortcode extends Tag {
	const TAG = 'course-search';
	const DEFAULT_TEMPLATE = 'courseSearch';
	const COURSE_LIST_TEMPLATE = 'list-template';

	protected SearchSettings $searchSettings;

	/**
	 * @param Container $registry
	 *
	 * @throws InjectionImpossibleException
	 */
	public function __construct(Container $registry) {
		$this->searchSettings = $registry->getInstance(SearchSettings::class);
		parent::__construct(__DIR__, self::DEFAULT_TEMPLATE, $registry);
	}

	public function buildTag(): string {
		$parser = $this->getNewParser();
		$parser->setData('listTemplate', $this->attributes[self::COURSE_LIST_TEMPLATE] ?? 'course' . $this->searchSettings->getOutputFormat());
		return $parser->parse($this->getTemplate());
	}
}