<?php

namespace Planaday\Html\NodeTags\Course\Details\Page;

use Planaday\Config\BasicEnumMappedSetting;
use Planaday\Config\BasicSettingsLog;
use Planaday\Config\EnumMappedSettings;
use Planaday\Config\FormGroupable;
use Planaday\Config\SettingsLoader;
use Planaday\Config\SettingsWithForm;
use Planaday\Config\SettingsWithUsageLog;
use Planaday\Platform\PlatformAbstraction\LocalizationController;
use Planaday\Utility\DependencyInjection\Attributes\Scoped;
use Planaday\Utility\FormBuilder\Conditions\InputValueCondition;
use Planaday\Utility\FormBuilder\InputFields\BoolInput;
use Planaday\Utility\FormBuilder\Structure;
use Planaday\Utility\FormBuilder\Structures\BasicGroup;
use Planaday\Utility\FormBuilder\Structures\CollapsibleGroup;
use Planaday\Utility\FormBuilder\Structures\QuestionCluster;

#[Scoped]
class DetailPageSettings implements EnumMappedSettings, SettingsWithForm, SettingsWithUsageLog {
	use FormGroupable;
	use BasicEnumMappedSetting;
	use BasicSettingsLog;
	
	protected bool $showSoobLabel = false;
	protected bool $showCode95Label = false;
	protected bool $showLabels = false;
	protected bool $showDayPartCount = true;
	protected bool $showLevelCourse = false;
	protected bool $showAvailability = false;
	protected bool $showStartGuaranteeLabel = false;
	protected bool $showMoneyBackLabel = false;
	protected bool $showFinancialInfo = false;
	protected bool $showPrice = true;
	protected bool $showPriceWithAndWithoutTax = false;
	protected bool $showIcons = false;
	protected bool $showELearningIcon = false;
	protected bool $showDescription = true;

	public function __construct(
		protected LocalizationController $translator,
		SettingsLoader $settingsLoader
	) {
		$settingsLoader->reloadData($this, DetailPageSettingsEnum::class);
	}

	protected function createFormGroup(): Structure {
		$t = function ( string $string ) {
			return $this->translator->translate( $string );
		};
		
		return ( new CollapsibleGroup() )
			->startCollapsed()
			->setIndex( DetailPageSettingsEnum::class )
			->setHeader( $t( "Details pagina instellingen" ) )
			->setDescription( $t( "Instellingen voor de details pagina" ) )
			->addContents(
				(new QuestionCluster())
					->setName($t("Zichtbare Labels"))
					->setDescription($t("Welke labels moeten zichtbaar zijn bij de cursus"))
					->addContents(
						(new BoolInput())
							->setIndex( DetailPageSettingsEnum::ShowSoobLabel->value )
							->setName( $t("SOOB"))
							->setDescription( $t("Toon het SOOB label bij de cursus") )
							->setDefaultValue( $this->showSoobLabel )
							->addSetCallback( function ( $value ) {
								$this->showSoobLabel = $value ?? $this->showSoobLabel;
							}),
						(new BoolInput())
							->setIndex( DetailPageSettingsEnum::ShowCode95Label->value )
							->setName( $t("Code 95"))
							->setDescription( $t("Toon het Code 95 label bij de cursus") )
							->setDefaultValue( $this->showCode95Label )
							->addSetCallback( function ( $value ) {
								$this->showCode95Label = $value ?? $this->showCode95Label;
							}),
						(new BoolInput())
							->setIndex( DetailPageSettingsEnum::ShowELearningIcon->value )
							->setName( $t("E-learning"))
							->setDescription( $t("Moet er een icoon worden getoond voor e-learning?") )
							->setDefaultValue( $this->showELearningIcon )
							->addSetCallback( function ( $value ) {
								$this->showELearningIcon = $value ?? $this->showELearningIcon;
							}),
						(new BoolInput())
							->setIndex( DetailPageSettingsEnum::ShowLabels->value )
							->setName( $t("Labels"))
							->setDescription( $t("Toon de labels bij de cursus") )
							->setDefaultValue( $this->showLabels )
							->addSetCallback( function ( $value ) {
								$this->showLabels = $value ?? $this->showLabels;
							}),
						(new BoolInput())
							->setIndex( DetailPageSettingsEnum::ShowDayPartCount->value )
							->setName( $t("Dagdeel aantal"))
							->setDescription( $t("Toon het dagdeel aantal bij de cursus") )
							->setDefaultValue( $this->showDayPartCount )
							->addSetCallback( function ( $value ) {
								$this->showDayPartCount = $value ?? $this->showDayPartCount;
							}),
						(new BoolInput())
							->setIndex( DetailPageSettingsEnum::ShowLevelCourse->value )
							->setName( $t("Niveau cursus"))
							->setDescription( $t("Toon het niveau bij de cursus") )
							->setDefaultValue( $this->showLevelCourse )
							->addSetCallback( function ( $value ) {
								$this->showLevelCourse = $value ?? $this->showLevelCourse;
							}),
						(new BoolInput())
							->setIndex( DetailPageSettingsEnum::ShowAvailability->value )
							->setName( $t("Beschikbare plaatsen"))
							->setDescription( $t("Toon de beschikbaarheid bij de cursus") )
							->setDefaultValue( $this->showAvailability )
							->addSetCallback( function ( $value ) {
								$this->showAvailability = $value ?? $this->showAvailability;
							}),
						(new BoolInput())
							->setIndex( DetailPageSettingsEnum::ShowStartGuaranteeLabel->value )
							->setName( $t("Start garantie"))
							->setDescription( $t("Toon het start garantie label bij de cursus") )
							->setDefaultValue( $this->showStartGuaranteeLabel )
							->addSetCallback( function ( $value ) {
								$this->showStartGuaranteeLabel = $value ?? $this->showStartGuaranteeLabel;
							}),
						(new BoolInput())
							->setIndex( DetailPageSettingsEnum::ShowMoneyBackLabel->value )
							->setName( $t("Geld terug garantie"))
							->setDescription( $t("Toon het geld terug label bij de cursus") )
							->setDefaultValue( $this->showMoneyBackLabel )
							->addSetCallback( function ( $value ) {
								$this->showMoneyBackLabel = $value ?? $this->showMoneyBackLabel;
							}),
						(new BoolInput())
							->setIndex( DetailPageSettingsEnum::ShowFinancialInfo->value )
							->setName($t("Financiële toelichting (Betalingsinstellingen)"))
							->setDescription($t("Toon de financiële informatie bij de cursus"))
							->setDefaultValue( $this->showFinancialInfo )
							->addSetCallback( function ( $value ) {
								$this->showFinancialInfo = $value ?? $this->showFinancialInfo;
							}),
						$showPriceQuestion = (new BoolInput())
							->setIndex( DetailPageSettingsEnum::ShowPrice->value )
							->setName( $t("Prijs"))
							->setDescription( $t("Toon de prijs bij de cursus") )
							->setDefaultValue( $this->showPrice )
							->addSetCallback( function ( $value ) {
								$this->showPrice = $value ?? $this->showPrice;
							}),
						(new BasicGroup())
							->addConditions(
								(new InputValueCondition($showPriceQuestion))->equals()->value(true)
							)->addContents(
								(new BoolInput())
									->setIndex( DetailPageSettingsEnum::ShowPriceWithAndWithoutTax->value )
									->setName( $t("Prijs inclusief en exclusief belasting"))
									->setDescription( $t("Toon de prijs inclusief en exclusief belasting bij de cursus") )
									->setDefaultValue( $this->showPriceWithAndWithoutTax )
									->addSetCallback( function ( $value ) {
										$this->showPriceWithAndWithoutTax = $value ?? $this->showPriceWithAndWithoutTax;
									})
							)
					),
				(new BoolInput())
					->setIndex( DetailPageSettingsEnum::ShowIcons->value)
					->setName( $t("Toon icoon"))
					->setDescription( $t("Toon iconen bij de labels") )
					->setDefaultValue( $this->showIcons )
					->addSetCallback( function ( $value ) {
						$this->showIcons = $value ?? $this->showIcons;
					}),
				(new BoolInput())
					->setIndex( DetailPageSettingsEnum::ShowDescription->value )
					->setName( $t("Omschrijving"))
					->setDescription( $t("Moet er een omschrijving worden getoond?") )
					->setDefaultValue( $this->showDescription )
					->addSetCallback( function ( $value ) {
						$this->showDescription = $value ?? $this->showDescription;
					}),
			);
	}

	public function getEnumMapping(): array {
		return [
			"values" => [
				DetailPageSettingsEnum::ShowSoobLabel->value => &$this->showSoobLabel,
				DetailPageSettingsEnum::ShowCode95Label->value => &$this->showCode95Label,
				DetailPageSettingsEnum::ShowLabels->value => &$this->showLabels,
				DetailPageSettingsEnum::ShowDayPartCount->value => &$this->showDayPartCount,
				DetailPageSettingsEnum::ShowLevelCourse->value => &$this->showLevelCourse,
				DetailPageSettingsEnum::ShowAvailability->value => &$this->showAvailability,
				DetailPageSettingsEnum::ShowStartGuaranteeLabel->value => &$this->showStartGuaranteeLabel,
				DetailPageSettingsEnum::ShowMoneyBackLabel->value => &$this->showMoneyBackLabel,
				DetailPageSettingsEnum::ShowFinancialInfo->value => &$this->showFinancialInfo,
				DetailPageSettingsEnum::ShowPrice->value => &$this->showPrice,
				DetailPageSettingsEnum::ShowPriceWithAndWithoutTax->value => &$this->showPriceWithAndWithoutTax,
				DetailPageSettingsEnum::ShowIcons->value => &$this->showIcons,
				DetailPageSettingsEnum::ShowELearningIcon->value => &$this->showELearningIcon,
				DetailPageSettingsEnum::ShowDescription->value => &$this->showDescription,
				
			],
			"subGroups" => [],
			"subGroupAliases" => []
		];
	}

	public function isShowSoobLabel(): bool {
		$this->logUse(DetailPageSettingsEnum::ShowSoobLabel);
		return $this->showSoobLabel;
	}

	public function isShowCode95Label(): bool {
		$this->logUse(DetailPageSettingsEnum::ShowCode95Label);
		return $this->showCode95Label;
	}

	public function isShowLabels(): bool {
		$this->logUse(DetailPageSettingsEnum::ShowLabels);
		return $this->showLabels;
	}

	public function isShowDayPartCount(): bool {
		$this->logUse(DetailPageSettingsEnum::ShowDayPartCount);
		return $this->showDayPartCount;
	}

	public function isShowLevelCourse(): bool {
		$this->logUse(DetailPageSettingsEnum::ShowLevelCourse);
		return $this->showLevelCourse;
	}

	public function isShowAvailability(): bool {
		$this->logUse(DetailPageSettingsEnum::ShowAvailability);
		return $this->showAvailability;
	}

	public function isShowStartGuaranteeLabel(): bool {
		$this->logUse(DetailPageSettingsEnum::ShowStartGuaranteeLabel);
		return $this->showStartGuaranteeLabel;
	}

	public function isShowMoneyBackLabel(): bool {
		$this->logUse(DetailPageSettingsEnum::ShowMoneyBackLabel);
		return $this->showMoneyBackLabel;
	}

	public function isShowFinancialInfo(): bool {
		$this->logUse(DetailPageSettingsEnum::ShowFinancialInfo);
		return $this->showFinancialInfo;
	}

	public function isShowPrice(): bool {
		$this->logUse(DetailPageSettingsEnum::ShowPrice);
		return $this->showPrice;
	}

	public function isShowPriceWithAndWithoutTax(): bool {
		$this->logUse(DetailPageSettingsEnum::ShowPriceWithAndWithoutTax);
		return $this->showPriceWithAndWithoutTax;
	}

	public function isShowIcons(): bool {
		$this->logUse(DetailPageSettingsEnum::ShowIcons);
		return $this->showIcons;
	}

	public function isShowELearningIcon(): bool {
		$this->logUse(DetailPageSettingsEnum::ShowELearningIcon);
		return $this->showELearningIcon;
	}

	public function isShowDescription(): bool {
		$this->logUse(DetailPageSettingsEnum::ShowDescription);
		return $this->showDescription;
	}
}