<?php

/**
 * This file contains the DefaultElementSettingsPlacement class for managing element settings placement.
 *
 * @package FormEnhancer\FluentForm\Fields\Helpers
 */

namespace FormEnhancer\FluentForm\Fields\Helpers;

/**
 * Class DefaultElementSettingsPlacement
 *
 * Manages the placement of settings for form elements.
 */
class DefaultElementSettingsPlacement
{
	/**
	 * Singleton instance
	 *
	 * @var DefaultElementSettingsPlacement|null
	 */
	private static $instance = null;

	/**
	 * Default element settings placement configuration
	 *
	 * @var array
	 */
	private static $defaultElementsSettingsPlacement = [];

	/**
	 * Private constructor to prevent direct instantiation
	 */
	private function __construct()
	{
		self::$defaultElementsSettingsPlacement = \fluentformLoadFile('Services/FormBuilder/ElementSettingsPlacement.php');
	}

	/**
	 * Get singleton instance
	 *
	 * @return DefaultElementSettingsPlacement
	 */
	public static function getInstance()
	{
		if (self::$instance == null) {
			self::$instance = new DefaultElementSettingsPlacement();
		}

		return self::$instance;
	}

	/**
	 * Get all settings placement configuration
	 *
	 * @return array
	 */
	private function getSettingsPlacement()
	{
		return self::$defaultElementsSettingsPlacement;
	}

	/**
	 * Get settings placement for a specific input type and tab
	 *
	 * @param string $input_type The input type to get settings for.
	 * @param string $tab The settings tab (general or advanced).
	 * @return array|false Settings array or false if not found.
	 */
	public function getSettingPlacement($input_type, $tab = 'general')
	{
		if (!\in_array($tab, ['general', 'advanced'], true)) {
			return false;
		}

		$elements = $this->getSettingsPlacement();

		if (!isset($elements[$input_type][$tab])) {
			return false;
		}

		return $elements[$input_type][$tab];
	}
}
