<?php
/**
 * Custom Site Identity Option Class
 *
 * @package errigal
 * @since 1.1.0
 */

namespace Errigal\Customiser;

defined( 'ABSPATH' ) || exit;

use Errigal\Constant\Errigal_Header_Class as Header_Class;
use Errigal\Customiser\Errigal_Custom_Site_Identity as Site_Identity;
use Errigal\Shared\{
	Errigal_Site_Info as Site_Info,
	Errigal_Utility as Utility,
};

/**
 * This class is in charge of site identity customisation via customiser.
 *
 * @since 1.1.0
 */
class Errigal_Custom_Site_Identity_Option extends Errigal_Custom_Option_Base {
	/**
	 * Active callback: can_show_branding_text_control.
	 *
	 * @since 1.2.0
	 *
	 * @var string
	 */
	private const ACTIVE_CALLBACK_CAN_SHOW_BRANDING_TEXT_CONTROL = 'can_show_branding_text_control';

	/**
	 * Gets controls args.
	 *
	 * @since 1.1.0
	 *
	 * @return array
	 */
	public function get_controls_args() {
		return array(
			self::CONTROLS_TO_UPDATE => array(
				Site_Identity::ID_WP_BLOGNAME        => array(
					self::CUSTOMISE_ARGS_SETTING => array(
						self::SETTING_TRANSPORT => self::SETTING_TRANSPORT_POST_MESSAGE,
					),
					self::CUSTOMISE_ARGS_CONTROL => array(
						self::CONTROL_ACTIVE_CALLBACK => $this->get_callback(
							array( $this, self::ACTIVE_CALLBACK_CAN_SHOW_BRANDING_TEXT_CONTROL )
						),
					),
					self::CUSTOMISE_ARGS_PARTIAL => array(
						self::PARTIAL_SELECTOR        => Utility::get_selector( Header_Class::BRAND_TITLE ),
						/**
						 * Renders blog name.
						 *
						 * @since 1.1.0
						 *
						 * @return void
						 */
						self::PARTIAL_RENDER_CALLBACK => function () {
							echo esc_html( Site_Info::get_title() );
						},
					),
				),
				Site_Identity::ID_WP_BLOGDESCRIPTION => array(
					self::CUSTOMISE_ARGS_SETTING => array(
						self::SETTING_TRANSPORT => self::SETTING_TRANSPORT_POST_MESSAGE,
					),
					self::CUSTOMISE_ARGS_CONTROL => array(
						self::CONTROL_ACTIVE_CALLBACK => $this->get_callback(
							array( $this, self::ACTIVE_CALLBACK_CAN_SHOW_BRANDING_TEXT_CONTROL )
						),
					),
					self::CUSTOMISE_ARGS_PARTIAL => array(
						self::PARTIAL_SELECTOR        => Utility::get_selector( Header_Class::BRAND_DESCRIPTION ),
						/**
						 * Renders blog description.
						 *
						 * @since 1.1.0
						 *
						 * @return void
						 */
						self::PARTIAL_RENDER_CALLBACK => function () {
							echo esc_html( Site_Info::get_description() );
						},
					),
				),
				Site_Identity::ID_WP_CUSTOM_LOGO     => array(
					self::CUSTOMISE_ARGS_PARTIAL => array(
						self::PARTIAL_SELECTOR        => Utility::get_selector( Header_Class::BRANDING_CONTAINER ),
						/**
						 * Renders branding.
						 *
						 * @since 1.1.0
						 *
						 * @return void
						 */
						self::PARTIAL_RENDER_CALLBACK => function () {
							get_template_part( 'template-parts/component/header/site-header/branding' );
						},
					),
				),
			),
			self::CONTROLS_TO_REMOVE => array(
				Site_Identity::ID_WP_DISPLAY_HEADER_TEXT,
			),
		);
	}

	/**
	 * Active callback: Determines whether branding text control can be displayed.
	 *
	 * @since 1.2.0
	 *
	 * @return bool
	 */
	protected function can_show_branding_text_control() {
		return ! has_custom_logo();
	}
}
