<?php
/**
 * Custom Option Base Class
 *
 * @package errigal
 * @since 1.0.0
 */

namespace Errigal\Customiser;

defined( 'ABSPATH' ) || exit;

use Errigal\Shared\Errigal_Validator as Validator;

/**
 * This class is in charge of providing shared custom option functions.
 *
 * @since 1.0.0
 */
abstract class Errigal_Custom_Option_Base {
	/**
	 * Controls to add.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const CONTROLS_TO_ADD = 'controls_to_add';

	/**
	 * Controls to update.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const CONTROLS_TO_UPDATE = 'controls_to_update';

	/**
	 * Controls to remove.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const CONTROLS_TO_REMOVE = 'controls_to_remove';

	/**
	 * Customise args: setting.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const CUSTOMISE_ARGS_SETTING = 'setting';

	/**
	 * Customise args: control.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const CUSTOMISE_ARGS_CONTROL = 'control';

	/**
	 * Customise args: partial.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const CUSTOMISE_ARGS_PARTIAL = 'partial';

	/**
	 * Control: section.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_control/__construct/
	 *
	 * @var string
	 */
	public const CONTROL_SECTION = 'section';

	/**
	 * Control: type.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_control/__construct/
	 *
	 * @var string
	 */
	public const CONTROL_TYPE = 'type';

	/**
	 * Control: Type: checkbox.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_control/__construct/
	 *
	 * @var string
	 */
	public const CONTROL_TYPE_CHECKBOX = 'checkbox';

	/**
	 * Control: Type: textarea.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_control/__construct/
	 *
	 * @var string
	 */
	public const CONTROL_TYPE_TEXTAREA = 'textarea';

	/**
	 * Control: Type: radio.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_control/__construct/
	 *
	 * @var string
	 */
	public const CONTROL_TYPE_RADIO = 'radio';

	/**
	 * Control: Type: select.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_control/__construct/
	 *
	 * @var string
	 */
	public const CONTROL_TYPE_SELECT = 'select';

	/**
	 * Control: Type: Customise control label.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const CONTROL_TYPE_LABEL = Errigal_Customise_Control_Label::class;

	/**
	 * Control: Type: Customise control pro features.
	 *
	 * @since 1.1.0
	 *
	 * @var string
	 */
	public const CONTROL_TYPE_PRO_FEATURES = Errigal_Customise_Control_Pro_Features::class;

	/**
	 * Setting: sanitize_callback.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_setting/__construct/
	 *
	 * @var string
	 */
	public const SETTING_SANITIZE_CALLBACK = 'sanitize_callback';

	/**
	 * Setting: default.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_setting/__construct/
	 *
	 * @var string
	 */
	protected const SETTING_DEFAULT = 'default';

	/**
	 * Setting: transport.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_setting/__construct/
	 *
	 * @var string
	 */
	protected const SETTING_TRANSPORT = 'transport';

	/**
	 * Setting: Transport: postMessage.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_setting/__construct/
	 *
	 * @var string
	 */
	protected const SETTING_TRANSPORT_POST_MESSAGE = 'postMessage';

	/**
	 * Control: priority.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_control/__construct/
	 *
	 * @var string
	 */
	protected const CONTROL_PRIORITY = 'priority';

	/**
	 * Control: priority: Appearance: Colour scheme.
	 *
	 * @since 1.0.0
	 *
	 * @var int
	 */
	protected const CONTROL_PRIORITY_APPEARANCE_COLOUR_SCHEME = 1;

	/**
	 * Control: priority: Appearance: Background colour.
	 *
	 * @since 1.0.0
	 *
	 * @var int
	 */
	protected const CONTROL_PRIORITY_APPEARANCE_BACKGROUND_COLOUR = 2;

	/**
	 * Control: priority: Appearance: Site header colour.
	 *
	 * @since 1.0.0
	 *
	 * @var int
	 */
	protected const CONTROL_PRIORITY_APPEARANCE_SITE_HEADER_COLOUR = 3;

	/**
	 * Control: priority: Appearance: Heading style.
	 *
	 * @since 1.1.0
	 *
	 * @var int
	 */
	protected const CONTROL_PRIORITY_APPEARANCE_HEADING_STYLE = 4;

	/**
	 * Control: label.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_control/__construct/
	 *
	 * @var string
	 */
	protected const CONTROL_LABEL = 'label';

	/**
	 * Control: description.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_control/__construct/
	 *
	 * @var string
	 */
	protected const CONTROL_DESCRIPTION = 'description';

	/**
	 * Control: choices.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_control/__construct/
	 *
	 * @var string
	 */
	protected const CONTROL_CHOICES = 'choices';

	/**
	 * Control: active_callback.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_control/__construct/
	 *
	 * @var string
	 */
	protected const CONTROL_ACTIVE_CALLBACK = 'active_callback';

	/**
	 * Partial: selector.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_partial/__construct/
	 *
	 * @var string
	 */
	protected const PARTIAL_SELECTOR = 'selector';

	/**
	 * Partial: render_callback.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_partial/__construct/
	 *
	 * @var string
	 */
	protected const PARTIAL_RENDER_CALLBACK = 'render_callback';

	/**
	 * Partial: container_inclusive.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_partial/__construct/
	 *
	 * @var string
	 */
	protected const PARTIAL_CONTAINER_INCLUSIVE = 'container_inclusive';

	/**
	 * Partial: fallback_refresh.
	 *
	 * @since 1.1.0
	 *
	 * @link https://developer.wordpress.org/reference/classes/wp_customize_partial/__construct/
	 *
	 * @var string
	 */
	protected const PARTIAL_FALLBACK_REFRESH = 'fallback_refresh';

	/**
	 * Gets controls args.
	 *
	 * @since 1.1.0
	 *
	 * @return array
	 */
	abstract public function get_controls_args();

	/**
	 * Gets callback.
	 *
	 * @since 1.2.0
	 *
	 * @param callable $callback Callable to be called.
	 * @param mixed    ...$args  Optional. Zero or more parameters to be passed to callback.
	 * @return callable|string
	 */
	final protected function get_callback( $callback, ...$args ) {
		if ( ! is_callable( $callback ) ) {
				return '';
		}

		/**
		 * Calls callback.
		 *
		 * @since 1.2.0
		 *
		 * @param callable $callback Callable to be called.
		 * @param mixed    ...$args  Optional. Zero or more parameters to be passed to callback.
		 * @return mixed|null
		 */
		return function () use ( $callback, $args ) {
			return $callback( ...$args );
		};
	}
}
