<?php
/**
 * Customizer settings: blog/post pages
 *
 * @package Multi
 */

if ( ! defined( 'ABSPATH' ) ) {
	die;
}

/**
 * Registers customizer settings for blog
 */
class Multimagazine_Customize_Blog {

	/**
	 * Registers the blog section and fires the extension hook
	 *
	 * @param object $wp_customize Customizer object.
	 */
	public static function register_section( $wp_customize ) {
		$wp_customize->add_section(
			'blog',
			array(
				'title'    => __( 'Blog', 'multimagazine' ),
				'priority' => 55,
			)
		);
		do_action( 'multimagazine_customize_blog' );
	}

	/**
	 * Registers the post list layout setting
	 */
	public static function register_post_list_layout() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting(
			'multi_post_list_layout',
			'blog',
			array(
				0  => __( 'Large image (default)', 'multimagazine' ),
				1  => __( 'Full width image', 'multimagazine' ),
				2  => __( 'Medium image', 'multimagazine' ),
				3  => __( 'Date exposed', 'multimagazine' ),
				4  => __( '3 columns', 'multimagazine' ),
				5  => __( '2 columns', 'multimagazine' ),
				6  => __( 'Masonry fullwidth', 'multimagazine' ),
				7  => __( 'Masonry sidebar', 'multimagazine' ),
				8  => __( 'Masonry fullwidth 3 columns', 'multimagazine' ),
				9  => __( 'Modern - 2 columns', 'multimagazine' ),
				10 => __( 'Modern - 3 columns', 'multimagazine' ),
				11 => __( 'Modern - full width', 'multimagazine' ),
				13 => __( 'Modern - mix', 'multimagazine' ),
				14 => __( 'Fresh - mix', 'multimagazine' ),
				16 => __( 'Trendy - mix', 'multimagazine' ),
			),
			__( 'Post list layout', 'multimagazine' )
		);
	}

	/**
	 * Registers the search results layout setting
	 */
	public static function register_search_results_layout() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting(
			'multi_search_results_layout',
			'blog',
			array(
				0 => __( 'Large image (default)', 'multimagazine' ),
				1 => __( 'Full width image', 'multimagazine' ),
				2 => __( 'Medium image', 'multimagazine' ),
				3 => __( 'Date exposed', 'multimagazine' ),
				4 => __( '3 columns', 'multimagazine' ),
				5 => __( '2 columns', 'multimagazine' ),
				6 => __( 'Masonry fullwidth', 'multimagazine' ),
				7 => __( 'Masonry sidebar', 'multimagazine' ),
			),
			__( 'Search results layout', 'multimagazine' )
		);
	}

	/**
	 * Adds the post meta settings heading
	 */
	public static function register_post_meta_heading() {
		multimagazine_add_heading( 'multi_post_meta_settings_title', 'blog', __( 'Post meta visibility', 'multimagazine' ) );
	}

	/**
	 * Registers the post meta date setting
	 */
	public static function register_post_meta_date() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting(
			'multi_post_meta_date',
			'blog',
			array(
				'on'  => __( 'On (default)', 'multimagazine' ),
				'off' => __( 'Off', 'multimagazine' ),
			),
			__( 'Date of post', 'multimagazine' )
		);
	}

	/**
	 * Registers the post meta author setting
	 */
	public static function register_post_meta_author() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting(
			'multi_post_meta_author',
			'blog',
			array(
				'on'  => __( 'On (default)', 'multimagazine' ),
				'off' => __( 'Off', 'multimagazine' ),
			),
			__( 'Post author', 'multimagazine' )
		);
	}

	/**
	 * Registers the post meta categories setting
	 */
	public static function register_post_meta_categories() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting(
			'multi_post_meta_categories',
			'blog',
			array(
				'on'  => __( 'On (default)', 'multimagazine' ),
				'off' => __( 'Off', 'multimagazine' ),
			),
			__( 'Post categories', 'multimagazine' )
		);
	}

	/**
	 * Registers the postlist hide more setting
	 */
	public static function register_postlist_hide_more() {
		global $multimagazine_customize;
		$multimagazine_customize->checkbox_setting( 'multi_postlist_hide_more', 'blog', __( 'Hide more link in post lists', 'multimagazine' ) );
	}

	/**
	 * Registers the post layout setting
	 */
	public static function register_post_layout() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting(
			'multi_post_layout',
			'blog',
			array(
				'standard'                => __( 'Standard', 'multimagazine' ),
				'full-width-header'       => __( 'Full width headline', 'multimagazine' ),
				'full-width-header-image' => __( 'Full width headline with image', 'multimagazine' ),
			),
			__( 'Post layout', 'multimagazine' )
		);
	}

	/**
	 * Registers the top slider setting
	 */
	public static function register_top_slider() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting(
			'multi_top_slider',
			'blog',
			array(
				'off'      => __( 'Off', 'multimagazine' ),
				'featured' => __( 'Featured posts', 'multimagazine' ),
				'related'  => __( 'Related posts', 'multimagazine' ),
				'latest'   => __( 'Latest posts', 'multimagazine' ),
			),
			__( 'Top slider', 'multimagazine' ),
			__( 'Shows posts in a slider above content (may be overwritten by post/page settings)', 'multimagazine' )
		);
	}

	/**
	 * Registers the show post author setting
	 */
	public static function register_show_post_author() {
		global $multimagazine_customize;
		$multimagazine_customize->checkbox_setting( 'multi_show_post_author', 'blog', __( 'Show post author on post page', 'multimagazine' ) );
	}

	/**
	 * Registers the post author link setting
	 */
	public static function register_post_author_link() {
		global $multimagazine_customize;
		$multimagazine_customize->checkbox_setting( 'multi_post_author_link', 'blog', __( 'Enable link to author page', 'multimagazine' ) );
	}

	/**
	 * Registers the show related posts setting
	 */
	public static function register_show_related() {
		global $multimagazine_customize;
		$multimagazine_customize->range_setting(
			'multi_show_related',
			'blog',
			0,
			30,
			1,
			__( 'Show related posts', 'multimagazine' ),
			__( 'Enter a number to specify the number of posts to show (0 - disabled)', 'multimagazine' )
		);
	}

	/**
	 * Registers the load related posts setting
	 */
	public static function register_load_related() {
		global $multimagazine_customize;
		$multimagazine_customize->checkbox_setting( 'multi_load_related', 'blog', __( 'Load related posts when scrolling down', 'multimagazine' ), __( 'Works only if related posts are enabled', 'multimagazine' ) );
	}

	/**
	 * Registers the load related posts with sidebar setting
	 */
	public static function register_load_related_with_sidebar() {
		global $multimagazine_customize;
		$multimagazine_customize->checkbox_setting( 'multi_load_related_with_sidebar', 'blog', __( 'Load related posts when scrolling down (including sidebars)', 'multimagazine' ) );
	}

	/**
	 * Registers the show featured posts setting
	 */
	public static function register_show_featured() {
		global $multimagazine_customize;
		$multimagazine_customize->range_setting(
			'multi_show_featured',
			'blog',
			0,
			30,
			1,
			__( 'Show featured posts', 'multimagazine' ),
			__( 'Enter a number to specify the number of posts to show (0 - disabled)', 'multimagazine' )
		);
	}

	/**
	 * Registers the show latest posts setting
	 */
	public static function register_show_latest() {
		global $multimagazine_customize;
		$multimagazine_customize->range_setting(
			'multi_show_latest',
			'blog',
			0,
			30,
			1,
			__( 'Show latest posts', 'multimagazine' ),
			__( 'Enter a number to specify the number of posts to show (0 - disabled)', 'multimagazine' )
		);
	}

	/**
	 * Registers the related/featured/latest layout setting
	 */
	public static function register_related_layout() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting(
			'multi_related_layout',
			'blog',
			array(
				'list'   => __( 'Scrolled list', 'multimagazine' ),
				'grid'   => __( 'Grid', 'multimagazine' ),
				'slider' => __( 'Slider', 'multimagazine' ),
			),
			__( 'Layout of related/featured/latest post list', 'multimagazine' )
		);
	}

	/**
	 * Registers the async post list loading setting
	 */
	public static function register_load_postlist() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting(
			'multi_load_postlist',
			'blog',
			array(
				'off'    => __( 'Off', 'multimagazine' ),
				'auto'   => __( 'Automatically', 'multimagazine' ),
				'button' => __( '"Load more" button', 'multimagazine' ),
			),
			__( 'Asynchronously load posts into post list', 'multimagazine' )
		);
	}

	/**
	 * Adds the other options heading
	 */
	public static function register_other_options_heading() {
		multimagazine_add_heading( 'multi_blog_other_options', 'blog', __( 'Other options', 'multimagazine' ) );
	}

	/**
	 * Registers the sticky post nav setting
	 */
	public static function register_sticky_post_nav() {
		global $multimagazine_customize;
		$multimagazine_customize->checkbox_setting( 'multi_sticky_post_nav', 'blog', __( 'Enable sticky links to previous/next posts', 'multimagazine' ) );
	}

	/**
	 * Registers the post header setting
	 */
	public static function register_post_header() {
		global $multimagazine_customize;
		$multimagazine_customize->checkbox_setting( 'multi_post_header', 'blog', __( 'Enable special sticky header for posts', 'multimagazine' ) );
	}

	/**
	 * Registers the post header mobile setting
	 */
	public static function register_post_header_mobile() {
		global $multimagazine_customize;
		$multimagazine_customize->checkbox_setting( 'multi_post_header_mobile', 'blog', __( 'Enable special sticky header for posts also on mobile', 'multimagazine' ) );
	}

	/**
	 * Registers the show featured image setting
	 */
	public static function register_show_featured_image() {
		global $multimagazine_customize;
		$multimagazine_customize->checkbox_setting( 'multi_show_featured_image', 'blog', __( 'Show featured images in posts and pages', 'multimagazine' ) );
	}

	/**
	 * Registers the scroll progress setting
	 */
	public static function register_scroll_progress() {
		global $multimagazine_customize;
		$multimagazine_customize->checkbox_setting( 'multi_scroll_progress', 'blog', __( 'Show post scroll progress in special header', 'multimagazine' ) );
	}
}

add_action( 'customize_register', array( 'Multimagazine_Customize_Blog', 'register_section' ) );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_post_list_layout' ), 10 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_search_results_layout' ), 15 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_post_meta_heading' ), 20 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_post_meta_date' ), 25 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_post_meta_author' ), 30 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_post_meta_categories' ), 35 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_postlist_hide_more' ), 40 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_post_layout' ), 45 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_top_slider' ), 50 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_show_post_author' ), 55 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_post_author_link' ), 60 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_show_related' ), 65 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_load_related' ), 70 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_load_related_with_sidebar' ), 75 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_show_featured' ), 80 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_show_latest' ), 85 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_related_layout' ), 90 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_load_postlist' ), 95 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_other_options_heading' ), 100 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_sticky_post_nav' ), 105 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_post_header' ), 110 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_post_header_mobile' ), 115 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_show_featured_image' ), 120 );
add_action( 'multimagazine_customize_blog', array( 'Multimagazine_Customize_Blog', 'register_scroll_progress' ), 125 );
