<?php

namespace Planaday\Config\OptionGroups\Course\Calendar;

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

class CalendarOptions extends OptionGroup implements ComponentRegistryShortCut {
	private const NAME = 'Kalender';

	private const DESCRIPTION = 'Instellingen voor de kalender functie';

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

	/** @var StringOption<null> */
	private $textColor;

	/** @var StringOption<null> */
	private $backgroundColor;

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

	/** @var BoolOption */
	private $showAllDayParts;

	public function __construct( string $index, array $data ) {
		$this->backgroundColor = new StringOption(
			CalendarOptionsEnum::BACKGROUND_COLOR,
			'Achtergrond kleur',
			'Achtergrond kleur van de kalender, vul deze waarde in als HEX. Bijvoorbeeld: #CCCCCC',
			$data[CalendarOptionsEnum::BACKGROUND_COLOR] ?? null,
			null
		);

		$this->textColor = new StringOption(
			CalendarOptionsEnum::TEXT_COLOR,
			'Tekst kleur',
			'Tekst kleur van de kalender, vul deze waarde in als HEX. Bijvoorbeeld: #FFFFFF',
			$data[CalendarOptionsEnum::TEXT_COLOR] ?? null,
			null
		);

		$this->showMouseoverText = new BoolOption(
			CalendarOptionsEnum::SHOW_MOUSEOVER_TEXT,
			'Toon tekst bij hover',
			'Toon tekst bij hover',
			$data[CalendarOptionsEnum::SHOW_MOUSEOVER_TEXT] ?? null,
			true
		);

		$this->showAllDayParts = new BoolOption(
			CalendarOptionsEnum::SHOW_ALL_DAY_PARTS,
			'Alle dagdelen tonen',
			'Alle dagdelen van de cursus tonen ipv alleen het eerste dagdeel?',
			$data[CalendarOptionsEnum::SHOW_ALL_DAY_PARTS] ?? null,
			false
		);

		$this->calendarVersion = new RadioOption(
			CalendarOptionsEnum::CALENDAR_VERSION,
			'Kalender versie',
			'Welke versie van de kalender moet worden gebruikt?',
			$data[CalendarOptionsEnum::CALENDAR_VERSION] ?? null,
			1,
			[
				0 => 'v3 (legacy)',
				1 => 'v6'
			]
		);

		$layout = [
			$this->backgroundColor,
			$this->textColor,
			$this->showMouseoverText,
			$this->showAllDayParts,
			$this->calendarVersion
		];

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

	/**
	 * @return StringOption<null>
	 */
	public function backgroundColor(): StringOption {
		return $this->backgroundColor;
	}

	/**
	 * @return StringOption<null>
	 */
	public function textColor(): StringOption {
		return $this->textColor;
	}

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

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

	/**
	 * @return RadioOption
	 */
	public function calendarVersion(): RadioOption {
		return $this->calendarVersion;
	}

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