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

namespace Errigal\Customiser;

defined( 'ABSPATH' ) || exit;

use Errigal\Constant\{
	Errigal_Footer_Class as Footer_Class,
	Errigal_WP_Function as WP_Function,
};
use Errigal\Customiser\Errigal_Custom_Footer as Footer;
use Errigal\Shared\{
	Errigal_Html_Builder as Html_Builder,
	Errigal_Site_Info as Site_Info,
	Errigal_Utility as Utility,
	Errigal_Validator as Validator,
};

/**
 * This class is in charge of site footer customisation via customiser.
 *
 * @since 1.1.0
 */
class Errigal_Custom_Footer_Option extends Errigal_Custom_Option_Base {
	/**
	 * Gets controls args.
	 *
	 * @since 1.1.0
	 *
	 * @return array
	 */
	public function get_controls_args() {
		return array(
			self::CONTROLS_TO_ADD => array(
				Footer::ID_COPYRIGHT_TEXT => array(
					self::CUSTOMISE_ARGS_SETTING => array(
						self::SETTING_DEFAULT           => Footer::get_default_copyright_text(),
						self::SETTING_TRANSPORT         => self::SETTING_TRANSPORT_POST_MESSAGE,
						self::SETTING_SANITIZE_CALLBACK => WP_Function::WP_KSES_POST,
					),
					self::CUSTOMISE_ARGS_CONTROL => array(
						self::CONTROL_LABEL       => esc_html__( 'Display Copyright Text', 'errigal' ),
						self::CONTROL_DESCRIPTION => $this->get_description(),
						self::CONTROL_TYPE        => self::CONTROL_TYPE_TEXTAREA,
					),
					self::CUSTOMISE_ARGS_PARTIAL => array(
						self::PARTIAL_SELECTOR            => Utility::get_selector( Footer_Class::SITE_FOOTER_COPYRIGHT_TEXT ),
						/**
						 * Renders copyright text.
						 *
						 * @since 1.1.0
						 *
						 * @return void
						 */
						self::PARTIAL_RENDER_CALLBACK     => function () {
							get_template_part( 'template-parts/component/footer/site-footer/copyright-text' );
						},
						self::PARTIAL_CONTAINER_INCLUSIVE => true,
					),
				),
			),
		);
	}
	/**
	 * Gets description.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	private function get_description() {
		$theme_link   = Footer::get_theme_link();
		$html_builder = Html_Builder::create();

		return $html_builder->create_span()->get_element(
			esc_html__( 'You can use the shortcodes below.', 'errigal' )
		) .
		$html_builder->create_ul()->get_element(
			$html_builder->create_li()->get_element(
				esc_html(
					Utility::join(
						Utility::SEPARATOR_EQUALS_SPACED,
						Footer::SHORTCODE_COPYRIGHT,
						Footer::COPYRIGHT_SIGN
					)
				)
			) .
			$html_builder->create_li()->get_element(
				esc_html(
					Utility::join(
						Utility::SEPARATOR_EQUALS_SPACED,
						Footer::SHORTCODE_CURRENT_YEAR,
						Footer::get_current_year()
					)
				)
			) .
			$html_builder->create_li()->get_element(
				esc_html(
					Utility::join(
						Utility::SEPARATOR_EQUALS_SPACED,
						Footer::SHORTCODE_SITE_TITLE,
						Site_Info::get_title()
					)
				)
			) .
			(
				Validator::is_non_empty_string( $theme_link )
					? $html_builder->create_li()->get_element(
						esc_html(
							Utility::join(
								Utility::SEPARATOR_EQUALS_SPACED,
								Footer::SHORTCODE_THEME_LINK,
								wp_strip_all_tags( $theme_link )
							)
						)
					)
					: ''
			)
		) .
		$html_builder->create_span()->get_element(
			esc_html__( 'You can also use basic HTML tags.', 'errigal' )
		);
	}
}
