<?php

namespace Planaday\Html\NodeTags\Course\ListTag\TemplateSettings;

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\InputFields\BoolInput;
use Planaday\Utility\FormBuilder\Structure;
use Planaday\Utility\FormBuilder\Structures\CollapsibleGroup;

#[Scoped]
class CalendarTemplateSettings  implements EnumMappedSettings, SettingsWithForm, SettingsWithUsageLog {
	use FormGroupable;
	use BasicEnumMappedSetting;
	use BasicSettingsLog;

	protected bool $showMouseoverText = true;
	protected bool $showAllDayParts = false;

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

	/**
	 * @return array{values:mixed[], subGroups:array[], subGroupAliases:string[]}
	 */
	public function getEnumMapping(): array {
		return [
			"values" => [
				CalendarTemplateSettingsEnum::ShowMouseoverText->value => &$this->showMouseoverText,
				CalendarTemplateSettingsEnum::ShowAllDayParts->value => &$this->showAllDayParts,
			],
			"subGroups" => [],
			"subGroupAliases" => []
		];
	}

	protected function createFormGroup(): Structure {
		$t = function ( string $string ) {
			return $this->translator->translate( $string );
		};

		return ( new CollapsibleGroup() )
			->startCollapsed()
			->setIndex( CalendarTemplateSettingsEnum::class )
			->setHeader( $t( "Kalender instellingen" ) )
			->setDescription( $t( "Stel in hoe de kalender getoond moet worden" ) )
			->addContents(
				( new BoolInput() )
					->setIndex( CalendarTemplateSettingsEnum::ShowMouseoverText->value )
					->setName( $t("Toon tekst bij hover") )
					->setDescription( $t("Toon tekst bij hover") )
					->setDefaultValue( $this->showMouseoverText )
					->addSetCallback( function ( $value ) {
						$this->showMouseoverText = $value ?? $this->showMouseoverText;
					}),
				( new BoolInput() )
					->setIndex( CalendarTemplateSettingsEnum::ShowAllDayParts->value )
					->setName( $t("Alle dagdelen tonen") )
					->setDescription( $t("Alle dagdelen van de cursus tonen ipv alleen het eerste dagdeel?") )
					->setDefaultValue( $this->showAllDayParts )
					->addSetCallback( function ( $value ) {
						$this->showAllDayParts = $value ?? $this->showAllDayParts;
					})
			);
	}

	public function isShowMouseoverText(): bool {
		$this->logUse(CalendarTemplateSettingsEnum::ShowMouseoverText);
		return $this->showMouseoverText;
	}

	public function isShowAllDayParts(): bool {
		$this->logUse(CalendarTemplateSettingsEnum::ShowAllDayParts);
		return $this->showAllDayParts;
	}
}