<?php
/**
 * SectionType class.
 *
 * Defines available tab sections for the PowerWidget module.
 *
 * @package Ilabs\Firevert\Modules\PowerWidget\Services\Type
 */

declare( strict_types=1 );

namespace Ilabs\Firevert\Modules\PowerWidget\Services\Type;

use Ilabs\Firevert\Modules\PowerWidget\Services\Form\AppearanceFormHandler;
use Ilabs\Firevert\Modules\PowerWidget\Services\Form\ProductsFormHandler;
use Ilabs\Firevert\Modules\PowerWidget\Services\Form\SettingsFormHandler;

/**
 * Class SectionType.
 */
final class SectionType {

	public const SETTINGS   = 'settings';
	public const APPEARANCE = 'appearance';
	public const PRODUCTS   = 'products';

	/**
	 * Returns all available section slugs => labels.
	 *
	 * @return array<string, string>
	 */
	public static function get_all(): array {
		return array(
			self::SETTINGS   => __( 'Widget Settings', 'firevert' ),
			self::APPEARANCE => __( 'Widget Appearance', 'firevert' ),
			self::PRODUCTS   => __( 'Products', 'firevert' ),
		);
	}

	/**
	 * Maps section slugs to form handler classes.
	 *
	 * @return array<string, string> section => FormHandler::class
	 */
	public static function get_handler_map(): array {
		return array(
			self::APPEARANCE => AppearanceFormHandler::class,
			self::SETTINGS   => SettingsFormHandler::class,
			self::PRODUCTS   => ProductsFormHandler::class,
		);
	}

	/**
	 * Returns true if the section exists.
	 *
	 * @param string $section Section slug.
	 *
	 * @return bool
	 */
	public static function exists( string $section ): bool {
		return array_key_exists( $section, self::get_all() );
	}

	/**
	 * Returns label for a given section.
	 *
	 * @param string $section Section slug.
	 *
	 * @return string|null
	 */
	public static function get_label( string $section ): ?string {
		$all = self::get_all();

		return $all[ $section ] ?? null;
	}

	/**
	 * Returns FormHandler class name for given section.
	 *
	 * @param string $section Section slug.
	 *
	 * @return string|null
	 */
	public static function get_handler( string $section ): ?string {
		$map = self::get_handler_map();

		return $map[ $section ] ?? null;
	}
}
