<?php

namespace Planaday\Config\OptionGroups\Course\Search;

use Planaday\Config\OptionGroups\Course\CourseOptions;
use Planaday\Config\OptionGroups\OptionCluster;
use Planaday\Config\OptionGroups\OptionGroup;
use Planaday\Config\OptionTypes\BoolOption;
use Planaday\Config\OptionTypes\RadioOption;
use Planaday\Utility\DependencyInjection\ComponentRegistry;
use Planaday\Utility\DependencyInjection\ComponentRegistryShortCut;

class SearchOptions extends OptionGroup implements ComponentRegistryShortCut {
	private const NAME = 'Zoek';

	private const DESCRIPTION = 'Instellingen voor de zoekfunctie';

	/** @var BoolOption<bool> */
	private $askTitle;

	/** @var BoolOption<bool> */
	private $askLocation;

	/** @var BoolOption<bool> */
	private $askLabels;

	/** @var BoolOption<bool> */
	private $askCode95;

	/** @var BoolOption<bool> */
	private $askSoob;

	/** @var BoolOption<bool> */
	private $askElearning;

	/** @var RadioOption */
	private $outputFormat;

	/** @var BoolOption<bool> */
	private $askStap;

	public function __construct( string $index, array $data ) {
		$this->askTitle = new BoolOption(
			SearchOptionsEnum::ASK_TITLE,
			'Vraag naar titel',
			'Vraag naar de titel van de cursus',
			$data[SearchOptionsEnum::ASK_TITLE] ?? null,
			true
		);

		$this->askLocation = new BoolOption(
			SearchOptionsEnum::ASK_LOCATION,
			'Vraag naar locatie',
			'Vraag naar de locatie van de cursus',
			$data[SearchOptionsEnum::ASK_LOCATION] ?? null,
			false
		);

		$this->askLabels = new BoolOption(
			SearchOptionsEnum::ASK_LABELS,
			'Vraag naar labels',
			'Vraag naar de labels van de cursus',
			$data[SearchOptionsEnum::ASK_LABELS] ?? null,
			false
		);

		$this->askCode95 = new BoolOption(
			SearchOptionsEnum::ASK_CODE_95,
			'Vraag naar code 95',
			'Vraag naar of de cursus code 95 heeft',
			$data[SearchOptionsEnum::ASK_CODE_95] ?? null,
		false
		);

		$this->askSoob = new BoolOption(
			SearchOptionsEnum::ASK_SOOB,
			'Vraag naar SOOB',
			'Vraag naar of de cursus SOOB heeft',
			$data[SearchOptionsEnum::ASK_SOOB] ?? null,
			false
		);

		$this->askStap = new BoolOption(
			SearchOptionsEnum::ASK_STAP,
			'Vraag naar STAP',
			'Vraag naar of de cursus STAP heeft',
			$data[SearchOptionsEnum::ASK_STAP] ?? null,
			false
		);

		$this->askElearning = new BoolOption(
			SearchOptionsEnum::ASK_E_LEARNING,
			'Vraag naar E-learning',
			'Vraag naar of de cursus E-learning heeft.',
			$data[SearchOptionsEnum::ASK_E_LEARNING] ?? null,
			false
		);

		$this->outputFormat = new RadioOption(
			SearchOptionsEnum::OUTPUT_FORMAT,
			'Output formaat',
			'Hoe wordt de cursuslijst getoond?',
			$data[SearchOptionsEnum::OUTPUT_FORMAT] ?? null,
		0,
			[
				0 => 'Block',
				1 => 'Block2',
				2 => 'Table',
				3 => 'List',
			]
		);


		$layout = [
			new OptionCluster(
				'Zoekopties',
				'Op welke gegevens kan worden gezocht?',
				[
					'Titel' => $this->askTitle,
					'Locatie' => $this->askLocation,
					'Labels' => $this->askLabels,
					'Code95' => $this->askCode95,
					'Soob' => $this->askSoob,
					'Stap' => $this->askStap,
					'E-learning' => $this->askElearning,
				]
			),
			$this->outputFormat,
		];

		parent::__construct( $index, self::NAME, self::DESCRIPTION, $layout );
	}

	/**
	 * @return BoolOption<bool>
	 */
	public function askTitle(): BoolOption {
		return $this->askTitle;
	}

	/**
	 * @return BoolOption<bool>
	 */
	public function askLocation(): BoolOption {
		return $this->askLocation;
	}

	/**
	 * @return BoolOption<bool>
	 */
	public function askLabels(): BoolOption {
		return $this->askLabels;
	}

	/**
	 * @return BoolOption<bool>
	 */
	public function askCode95(): BoolOption {
		return $this->askCode95;
	}

	/**
	 * @return BoolOption<bool>
	 */
	public function askSoob(): BoolOption {
		return $this->askSoob;
	}

	/**
	 * @return BoolOption<bool>
	 */
	public function askElearning(): BoolOption {
		return $this->askElearning;
	}

	/**
	 * @return BoolOption<bool>
	 */
	public function askStap(): BoolOption {
		return $this->askStap;
	}

	public function outputFormat(): RadioOption {
		return $this->outputFormat;
	}

	public static function componentRegistryConstruct( ComponentRegistry $registry ) {
		return $registry->getComponent(CourseOptions::class)->searchOptions();
	}
}