<?php

namespace Planaday\Config\OptionGroups\Course\General;

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

class GeneralOptions extends OptionGroup implements ComponentRegistryShortCut {
	private const NAME = 'Algemeen';

	private const DESCRIPTION = 'Algemene instellingen voor cursussen';

	/** @var StringOption<string> */
	private $dayPartText;

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

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

	public function __construct( string $index, array $data ) {
		$this->dayPartText = new StringOption(
			GeneralOptionsEnum::DAY_PART_TEXT,
			"Naam die wordt getoond bij 'dagdelen'",
			"Bepaal zelf hoe de dagdelen worden genoemd. Bijvoorbeeld: 'dagen' of 'dagdelen'.",
			$data[ GeneralOptionsEnum::DAY_PART_TEXT ] ?? null,
			'dagen'
		);

		$this->includeOptionInCount = new BoolOption(
			GeneralOptionsEnum::INCLUDE_OPTION_IN_COUNT,
			"Opties meetellen",
			"Moeten openstaande opties (van inschrijvingen) ook meegeteld worden in beschikbaarheid?<br>" .
			"Zo ja, dan worden opties ook als 'bezet' meegeteld.",
			$data[ GeneralOptionsEnum::INCLUDE_OPTION_IN_COUNT ] ?? null,
			true
		);

		$this->skipELearningOnly = new BoolOption(
			GeneralOptionsEnum::SKIP_E_LEARNING_ONLY,
			"Cursussen met alleen e-learning overslaan?",
			"Moeten cursussen met alleen e-learning overgeslagen worden?",
			$data[ GeneralOptionsEnum::SKIP_E_LEARNING_ONLY ] ?? null,
			true
		);

		$layout = [
			$this->dayPartText,
			$this->includeOptionInCount,
			$this->skipELearningOnly
		];

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

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

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

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

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