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

namespace Errigal\Customiser;

defined( 'ABSPATH' ) || exit;

use Errigal\Customiser\Errigal_Custom_Typography as Typography;
use Errigal\Shared\Errigal_Validator as Validator;

/**
 * This class is in charge of typography customisation via customiser.
 *
 * @since 1.1.0
 */
class Errigal_Custom_Typography_Option extends Errigal_Custom_Option_Base {
	/**
	 * Gets controls args.
	 *
	 * @since 1.1.0
	 *
	 * @return array
	 */
	public function get_controls_args() {
		$controls_to_add = array();

		$font_select_labels = $this->get_font_select_labels();

		if ( Validator::is_associative_array( $font_select_labels ) ) {
			foreach ( $font_select_labels as $id => $args ) {
				if ( ! Validator::is_non_empty_string( $id ) ) {
					continue;
				}

				$args = wp_parse_args(
					$args,
					array(
						self::CONTROL_LABEL => '',
					)
				);

				$control_label = $args[ self::CONTROL_LABEL ];

				if ( ! Validator::is_non_empty_string( $control_label ) ) {
					continue;
				}

				$controls_to_add[ $id ] = array(
					self::CUSTOMISE_ARGS_SETTING => array(
						self::SETTING_DEFAULT   => Typography::get_default_font_id(),
						self::SETTING_TRANSPORT => self::SETTING_TRANSPORT_POST_MESSAGE,
					),
					self::CUSTOMISE_ARGS_CONTROL => array(
						self::CONTROL_LABEL   => esc_html( $control_label ),
						self::CONTROL_CHOICES => Typography::get_font_names(),
						self::CONTROL_TYPE    => self::CONTROL_TYPE_SELECT,
					),
				);
			}
		}

		$controls_to_add[ Typography::ID_FONT_SIZE ] = array(
			self::CUSTOMISE_ARGS_SETTING => array(
				self::SETTING_DEFAULT   => Typography::DEFAULT_FONT_SIZE,
				self::SETTING_TRANSPORT => self::SETTING_TRANSPORT_POST_MESSAGE,
			),
			self::CUSTOMISE_ARGS_CONTROL => array(
				self::CONTROL_LABEL   => esc_html__( 'Font Size', 'errigal' ),
				self::CONTROL_CHOICES => array(
					Typography::FONT_SIZE_SMALL    => esc_html__( 'Small', 'errigal' ),
					Typography::FONT_SIZE_STANDARD => esc_html__( 'Standard', 'errigal' ),
					Typography::FONT_SIZE_LARGE    => esc_html__( 'Large', 'errigal' ),
				),
				self::CONTROL_TYPE    => self::CONTROL_TYPE_RADIO,
			),
		);

		if ( ! Validator::is_associative_array( $controls_to_add ) ) {
			return array();
		}

		return array(
			self::CONTROLS_TO_ADD => $controls_to_add,
		);
	}

	/**
	 * Gets font select labels.
	 *
	 * @since 1.1.0
	 *
	 * @return array
	 */
	private function get_font_select_labels() {
		return array(
			Typography::ID_BASE_FONT    => array(
				self::CONTROL_LABEL => esc_html__( 'Base Font', 'errigal' ),
			),
			Typography::ID_HEADING_FONT => array(
				self::CONTROL_LABEL => esc_html__( 'Heading Font', 'errigal' ),
			),
		);
	}
}
