<?php
/**
 * Adds class aliases for backwards compatibility.
 *
 * @package   Kirki
 * @category  Core
 * @author    Themeum
 * @copyright Copyright (c) 2023, Themeum
 * @license   https://opensource.org/licenses/MIT
 * @since     0.1
 */

namespace Kirki\Compatibility;

/**
 * Adds class aliases for backwards compatibility.
 *
 * @since 0.1
 */
class Aliases
{

	/**
	 * An array of class aliases.
	 *
	 * @access private
	 * @since 0.1
	 * @var array
	 */
	private $aliases = array(
		'generic' => array(
			array('Kirki\Compatibility\Kirki', 'Kirki'),
			array('Kirki\Compatibility\Config', 'Kirki_Config'),
			array('Kirki\Compatibility\Control', 'Kirki_Control'),
			array('Kirki\Compatibility\Field', 'Kirki_Field'),
			array('Kirki\Util\Helper', 'Kirki_Helper'),
			array('Kirki\Compatibility\Init', 'Kirki_Init'),
			array('Kirki\L10n', 'Kirki_L10n'),
			array('Kirki\Compatibility\Modules', 'Kirki_Modules'),
			array('Kirki\Compatibility\Sanitize_Values', 'Kirki_Sanitize_Values'),
			array('Kirki\Compatibility\Section', 'Kirki_Section'),
			array('Kirki\Compatibility\Values', 'Kirki_Values'),
			array('Kirki\Util\Util', 'Kirki_Util'),
			array('Kirki\Compatibility\Framework', 'Kirki_Toolkit'),
			array('Kirki\Module\CSS', 'Kirki_Modules_CSS'),
			array('Kirki\Module\CSS\Output', 'Kirki_Output'),
			array('Kirki\Module\CSS\Generator', 'Kirki_Modules_CSS_Generator'),
			array('Kirki\Module\CSS\Property', 'Kirki_Output_Property'),
			array('Kirki\Module\CSS\Property\Font_Family', 'Kirki_Output_Property_Font_Family'),
			array('Kirki\Module\Preset', 'Kirki_Modules_Preset'),
			array('Kirki\Module\Tooltips', 'Kirki_Modules_Tooltips'),
			array('Kirki\Module\Webfonts', 'Kirki_Modules_Webfonts'),
			array('Kirki\Module\Webfonts\Google', 'Kirki_Fonts_Google'),
			array('Kirki\Module\Webfonts\Fonts', 'Kirki_Fonts'),
			array('Kirki\Module\Webfonts\Embed', 'Kirki_Modules_Webfonts_Embed'),
			array('Kirki\Module\Webfonts\Async', 'Kirki_Modules_Webfonts_Async'),
			array('Kirki\Module\Field_Dependencies', 'Kirki_Modules_Field_Dependencies'),
			array('Kirki\Module\Editor_Styles', 'Kirki_Modules_Gutenberg'),
			array('Kirki\Module\Selective_Refresh', 'Kirki_Modules_Selective_Refresh'),
			array('Kirki\Module\Postmessage', 'Kirki_Modules_Postmessage'),
			array('Kirki\Field\Background', 'Kirki_Field_Background'),
			array('Kirki\Field\CSS\Background', 'Kirki_Output_Field_Background'),
			array('Kirki\Field\Checkbox', 'Kirki_Field_Checkbox'),
			array('Kirki\Field\Checkbox_Switch', 'Kirki_Field_Switch'),
			array('Kirki\Field\Checkbox_Switch', 'Kirki\Field\Switch'), // Preventing typo.
			array('Kirki\Field\Checkbox_Toggle', 'Kirki_Field_Toggle'),
			array('Kirki\Field\Checkbox_Toggle', 'Kirki\Field\Toggle'), // Preventing typo.
			array('Kirki\Field\Code', 'Kirki_Field_Code'),
			array('Kirki\Field\Color', 'Kirki_Field_Color'),
			array('Kirki\Field\Color', 'Kirki_Field_Color_Alpha'),
			array('Kirki\Field\Color_Palette', 'Kirki_Field_Color_Palette'),
			array('Kirki\Field\Custom', 'Kirki_Field_Custom'),
			array('Kirki\Field\Dashicons', 'Kirki_Field_Dashicons'),
			array('Kirki\Field\Date', 'Kirki_Field_Date'),
			array('Kirki\Field\Dimension', 'Kirki_Field_Dimension'),
			array('Kirki\Field\Dimensions', 'Kirki_Field_Dimensions'),
			array('Kirki\Field\CSS\Dimensions', 'Kirki_Output_Field_Dimensions'),
			array('Kirki\Field\Dimensions', 'Kirki_Field_Spacing'),
			array('Kirki\Field\Dimensions', 'Kirki\Field\Spacing'),
			array('Kirki\Field\Editor', 'Kirki_Field_Editor'),
			array('Kirki\Field\FontAwesome', 'Kirki_Field_FontAwesome'),
			array('Kirki\Field\Generic', 'Kirki_Field_Kirki_Generic'),
			array('Kirki\Field\Generic', 'Kirki_Field_Generic'),
			array('Kirki\Field\Text', 'Kirki_Field_Text'),
			array('Kirki\Field\Textarea', 'Kirki_Field_Textarea'),
			array('Kirki\Field\URL', 'Kirki_Field_URL'),
			array('Kirki\Field\URL', 'Kirki_Field_Link'),
			array('Kirki\Field\URL', 'Kirki\Field\Link'),
			array('Kirki\Field\Image', 'Kirki_Field_Image'),
			array('Kirki\Field\CSS\Image', 'Kirki_Output_Field_Image'),
			array('Kirki\Field\Multicheck', 'Kirki_Field_Multicheck'),
			array('Kirki\Field\Multicolor', 'Kirki_Field_Multicolor'),
			array('Kirki\Field\CSS\Multicolor', 'Kirki_Output_Field_Multicolor'),
			array('Kirki\Field\Number', 'Kirki_Field_Number'),
			array('Kirki\Field\Palette', 'Kirki_Field_Palette'),
			array('Kirki\Field\Repeater', 'Kirki_Field_Repeater'),
			array('Kirki\Field\Dropdown_Pages', 'Kirki_Field_Dropdown_Pages'),
			array('Kirki\Field\Preset', 'Kirki_Field_Preset'),
			array('Kirki\Field\Select', 'Kirki_Field_Select'),
			array('Kirki\Field\Slider', 'Kirki_Field_Slider'),
			array('Kirki\Field\Sortable', 'Kirki_Field_Sortable'),
			array('Kirki\Field\Typography', 'Kirki_Field_Typography'),
			array('Kirki\Field\CSS\Typography', 'Kirki_Output_Field_Typography'),
			array('Kirki\Field\Upload', 'Kirki_Field_Upload'),
		),
		'customizer' => array(
			array('Kirki\Control\Base', 'Kirki_Control_Base'),
			array('Kirki\Control\Base', 'Kirki_Customize_Control'),
			array('Kirki\Control\Checkbox', 'Kirki_Control_Checkbox'),
			array('Kirki\Control\Checkbox_Switch', 'Kirki_Control_Switch'),
			array('Kirki\Control\Checkbox_Toggle', 'Kirki_Control_Toggle'),
			array('WP_Customize_Code_Editor_Control', 'Kirki_Control_Code'),
			array('Kirki\Control\Color', 'Kirki_Control_Color'),
			array('Kirki\Control\Color_Palette', 'Kirki_Control_Color_Palette'),
			array('WP_Customize_Cropped_Image_Control', 'Kirki_Control_Cropped_Image'),
			array('Kirki\Control\Custom', 'Kirki_Control_Custom'),
			array('Kirki\Control\Dashicons', 'Kirki_Control_Dashicons'),
			array('Kirki\Control\Date', 'Kirki_Control_Date'),
			array('Kirki\Control\Dimension', 'Kirki_Control_Dimension'),
			array('Kirki\Control\Editor', 'Kirki_Control_Editor'),
			array('Kirki\Control\Generic', 'Kirki_Control_Generic'),
			array('Kirki\Control\Image', 'Kirki_Control_Image'),
			array('Kirki\Control\Multicheck', 'Kirki_Control_Multicheck'),
			array('Kirki\Control\Generic', 'Kirki_Control_Number'),
			array('Kirki\Control\Palette', 'Kirki_Control_Palette'),
			array('Kirki\Control\Radio', 'Kirki_Control_Radio'),
			array('Kirki\Control\Radio_Buttonset', 'Kirki_Control_Radio_Buttonset'),
			array('Kirki\Control\Radio_Image', 'Kirki_Control_Radio_Image'),
			array('Kirki\Control\Radio_Image', 'Kirki_Controls_Radio_Image_Control'),
			array('Kirki\Control\Repeater', 'Kirki_Control_Repeater'),
			array('Kirki\Control\Select', 'Kirki_Control_Select'),
			array('Kirki\Control\Slider', 'Kirki_Control_Slider'),
			array('Kirki\Control\Sortable', 'Kirki_Control_Sortable'),
			array('Kirki\Control\Upload', 'Kirki_Control_Upload'),
			array('Kirki\Settings\Repeater', 'Kirki\Settings\Repeater_Setting'),
			array('Kirki\Settings\Repeater', 'Kirki_Settings_Repeater_Setting'),
			array('WP_Customize_Section', 'Kirki_Sections_Default_Section'),
			array('Kirki\Section_Types\Expanded', 'Kirki_Sections_Expanded_Section'),
			array('Kirki\Section_Types\Nested', 'Kirki_Sections_Nested_Section'),
			array('Kirki\Section_Types\Link', 'Kirki_Sections_Link_Section'),
			array('Kirki\Panel_Types\Nested', 'Kirki_Panels_Nested_Panel'),
		),
	);

	/**
	 * Constructor.
	 *
	 * @access public
	 * @since 0.1
	 */
	public function __construct()
	{
		$this->add_aliases();
		add_action('customize_register', array($this, 'add_customizer_aliases'));
	}

	/**
	 * Adds object aliases.
	 *
	 * @access public
	 * @since 0.1
	 * @return void
	 */
	public function add_aliases()
	{
		foreach ($this->aliases['generic'] as $item) {
			if (class_exists($item[0])) {
				class_alias($item[0], $item[1]);
			}
		}
	}

	/**
	 * Adds object aliases for classes that get instantiated on customize_register.
	 *
	 * @access public
	 * @since 0.1
	 * @return void
	 */
	public function add_customizer_aliases()
	{
		foreach ($this->aliases['customizer'] as $item) {
			if (class_exists($item[0])) {
				class_alias($item[0], $item[1]);
			}
		}
	}
}
