<?php

namespace Planaday\Config\OptionGroups\Booking\Form\Address;

use Planaday\Config\OptionGroups\Booking\BookingOptions;
use Planaday\Config\OptionGroups\OptionGroup;
use Planaday\Config\OptionTypes\BoolOption;
use Planaday\Utility\DependencyInjection\ComponentRegistry;
use Planaday\Utility\DependencyInjection\ComponentRegistryShortCut;

class AddressOptions extends OptionGroup implements ComponentRegistryShortCut {
	private const NAME = 'Adres';

	private const DESCRIPTION = 'De instellingen voor de adres invoervelden.';

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

	public function __construct( string $index, array $data ) {
		$this->askForNumberExtension = new BoolOption(
			AddressOptionsEnum::ASK_FOR_NUMBER_EXTENSION,
			'Huisnummer extensie vragen?',
			"Moet er een huisnummer extensie gevraagd worden?",
			$data[ AddressOptionsEnum::ASK_FOR_NUMBER_EXTENSION ] ?? null,
			true
		);

		$layout = [
			$this->askForNumberExtension
		];
		parent::__construct( $index, self::NAME, self::DESCRIPTION, $layout );
	}

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

	public static function componentRegistryConstruct( ComponentRegistry $registry ) {
		return $registry->getComponent(BookingOptions::class)->formOptions()->address();
	}
}