<?php

/**
 * This file contains the DefaultElements class for managing form element defaults.
 *
 * @package FormEnhancer\FluentForm\Fields\Helpers
 */

namespace FormEnhancer\FluentForm\Fields\Helpers;

/**
 * Class DefaultElements
 *
 * Manages default form elements using singleton pattern.
 */
class DefaultElements
{
	/**
	 * Singleton instance
	 *
	 * @var DefaultElements|null
	 */
	private static $instance = null;

	/**
	 * Default form elements configuration
	 *
	 * @var array
	 */
	private static $defaultElements = [];

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

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

		return self::$instance;
	}

	/**
	 * Get all default elements
	 *
	 * @return array
	 */
	private function getElements()
	{
		return self::$defaultElements;
	}

	/**
	 * Get a specific element configuration
	 *
	 * @param string $tab The element tab (general, advanced, or container).
	 * @param string $key The element key.
	 * @return array|false Element configuration array or false if not found.
	 */
	public function getElement($tab = 'general', $key = '')
	{
		if (!\in_array($tab, ['general', 'advanced', 'container'], true) || !$key) {
			return false;
		}

		$elements = $this->getElements();

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

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