<?php
/**
 * Customizer settings: sidebar
 *
 * @package Multi
 */

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

/**
 * Customizer settings for sidebars
 */
class Multimagazine_Customize_Sidebar {

	/**
	 * Returns sidebar position choices.
	 *
	 * @return array
	 */
	private static function sidebar_position_choices() {
		return array(
			'right' => __( 'Right (default)', 'multimagazine' ),
			'left'  => __( 'Left', 'multimagazine' ),
			'off'   => __( 'No sidebar', 'multimagazine' ),
		);
	}

	/**
	 * Registers the section and fires the extension hook.
	 *
	 * @param WP_Customize_Manager $wp_customize Customizer manager instance.
	 */
	public static function register_section( $wp_customize ) {
		$wp_customize->add_section(
			'sidebars',
			array(
				'title'    => __( 'Sidebar', 'multimagazine' ),
				'priority' => 45,
			)
		);
		do_action( 'multimagazine_customize_sidebars', $wp_customize );
	}

	/**
	 * Registers the last widget sticky setting.
	 */
	public static function register_last_widget_sticky() {
		global $multimagazine_customize;
		$multimagazine_customize->checkbox_setting( 'multi_last_widget_sticky', 'sidebars', __( 'Make last sidebar widget sticky', 'multimagazine' ) );
	}

	/**
	 * Registers the sidebar pos archive setting.
	 */
	public static function register_sidebar_pos_archive() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting( 'multi_sidebar_pos_archive', 'sidebars', self::sidebar_position_choices(), __( 'Sidebar position on Archive Pages', 'multimagazine' ) );
	}

	/**
	 * Registers the sidebar pos blog setting.
	 */
	public static function register_sidebar_pos_blog() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting( 'multi_sidebar_pos_blog', 'sidebars', self::sidebar_position_choices(), __( 'Sidebar position on Blog Page', 'multimagazine' ) );
	}

	/**
	 * Registers the sidebar pos post setting.
	 */
	public static function register_sidebar_pos_post() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting( 'multi_sidebar_pos_post', 'sidebars', self::sidebar_position_choices(), __( 'Sidebar position on Single Post Pages', 'multimagazine' ), __( 'May be overwritten by post settings.', 'multimagazine' ) );
	}

	/**
	 * Registers the sidebar pos page setting.
	 */
	public static function register_sidebar_pos_page() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting( 'multi_sidebar_pos_page', 'sidebars', self::sidebar_position_choices(), __( 'Sidebar position on Pages', 'multimagazine' ), __( 'May be overwritten by page settings.', 'multimagazine' ) );
	}

	/**
	 * Registers the sidebar pos search setting.
	 */
	public static function register_sidebar_pos_search() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting( 'multi_sidebar_pos_search', 'sidebars', self::sidebar_position_choices(), __( 'Sidebar position on Search Results Page', 'multimagazine' ) );
	}

	/**
	 * Registers the sidebar pos wc archive setting.
	 */
	public static function register_sidebar_pos_wc_archive() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting( 'multi_sidebar_pos_wc_archive', 'sidebars', self::sidebar_position_choices(), __( 'Sidebar position on WooCommerce product archive', 'multimagazine' ) );
	}

	/**
	 * Registers the sidebar pos wc category setting.
	 */
	public static function register_sidebar_pos_wc_category() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting( 'multi_sidebar_pos_wc_category', 'sidebars', self::sidebar_position_choices(), __( 'Sidebar position on WooCommerce product category pages', 'multimagazine' ) );
	}

	/**
	 * Registers the sidebar pos wc product setting.
	 */
	public static function register_sidebar_pos_wc_product() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting( 'multi_sidebar_pos_wc_product', 'sidebars', self::sidebar_position_choices(), __( 'Sidebar position on WooCommerce product pages', 'multimagazine' ) );
	}
}

add_action( 'customize_register', array( 'Multimagazine_Customize_Sidebar', 'register_section' ) );
add_action( 'multimagazine_customize_sidebars', array( 'Multimagazine_Customize_Sidebar', 'register_last_widget_sticky' ), 10 );
add_action( 'multimagazine_customize_sidebars', array( 'Multimagazine_Customize_Sidebar', 'register_sidebar_pos_archive' ), 15 );
add_action( 'multimagazine_customize_sidebars', array( 'Multimagazine_Customize_Sidebar', 'register_sidebar_pos_blog' ), 20 );
add_action( 'multimagazine_customize_sidebars', array( 'Multimagazine_Customize_Sidebar', 'register_sidebar_pos_post' ), 25 );
add_action( 'multimagazine_customize_sidebars', array( 'Multimagazine_Customize_Sidebar', 'register_sidebar_pos_page' ), 30 );
add_action( 'multimagazine_customize_sidebars', array( 'Multimagazine_Customize_Sidebar', 'register_sidebar_pos_search' ), 35 );
add_action( 'multimagazine_customize_sidebars', array( 'Multimagazine_Customize_Sidebar', 'register_sidebar_pos_wc_archive' ), 40 );
add_action( 'multimagazine_customize_sidebars', array( 'Multimagazine_Customize_Sidebar', 'register_sidebar_pos_wc_category' ), 45 );
add_action( 'multimagazine_customize_sidebars', array( 'Multimagazine_Customize_Sidebar', 'register_sidebar_pos_wc_product' ), 50 );
