<?php
/**
 * Custom Post Author 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_Post_Author as Post_Author;
use Errigal\Shared\Errigal_Utility as Utility;

/**
 * This class is in charge of post author customisation via customiser.
 *
 * @since 1.1.0
 */
class Errigal_Custom_Post_Author_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(
				Post_Author::ID_LABEL_POST_AUTHOR => array(
					self::CUSTOMISE_ARGS_CONTROL => array(
						self::CONTROL_LABEL => esc_html__( 'Post Author', 'errigal' ),
						self::CONTROL_TYPE  => self::CONTROL_TYPE_LABEL,
					),
				),
				Post_Author::ID_POST_AUTHOR       => array(
					self::CUSTOMISE_ARGS_SETTING => array(
						self::SETTING_DEFAULT   => Post_Author::DEFAULT_POST_AUTHOR,
						self::SETTING_TRANSPORT => self::SETTING_TRANSPORT_POST_MESSAGE,
					),
					self::CUSTOMISE_ARGS_CONTROL => array(
						self::CONTROL_LABEL => esc_html__( 'Show post author', 'errigal' ),
						self::CONTROL_TYPE  => self::CONTROL_TYPE_CHECKBOX,
					),
					self::CUSTOMISE_ARGS_PARTIAL => array(
						self::PARTIAL_SELECTOR         => Utility::get_selector( Header_Class::POST_HEADER_POST_METADATA ),
						/**
						 * Renders post metadata.
						 *
						 * @since 1.1.0
						 *
						 * @return void
						 */
						self::PARTIAL_RENDER_CALLBACK  => function () {
							while ( have_posts() ) {
								the_post();
								get_template_part( 'template-parts/component/shared/posted-by' );
								get_template_part( 'template-parts/component/shared/posted-on' );
							}
						},
						self::PARTIAL_FALLBACK_REFRESH => false,
					),
				),
			),
		);
	}
}
