<?php
/**
 * Customizer settings: top bar
 *
 * @package Multi
 */

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

/**
 * Customizer settings for top bar
 */
class Multimagazine_Customize_Top_Bar {

	/**
	 * 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(
			'top-bar',
			array(
				'title'    => __( 'Top bar', 'multimagazine' ),
				'priority' => 35,
			)
		);
		do_action( 'multimagazine_customize_top_bar', $wp_customize );
	}

	/**
	 * Registers the show topbar setting.
	 */
	public static function register_show_topbar() {
		global $multimagazine_customize;
		$multimagazine_customize->checkbox_setting( 'multi_show_topbar', 'top-bar', __( 'Show top bar', 'multimagazine' ) );
	}

	/**
	 * Registers the topbar sticky mobile setting.
	 */
	public static function register_topbar_sticky_mobile() {
		global $multimagazine_customize;
		$multimagazine_customize->checkbox_setting( 'multi_topbar_sticky_mobile', 'top-bar', __( 'Sticky on mobile', 'multimagazine' ) );
	}

	/**
	 * Registers the topbar sticky desktop setting.
	 */
	public static function register_topbar_sticky_desktop() {
		global $multimagazine_customize;
		$multimagazine_customize->checkbox_setting( 'multi_topbar_sticky_desktop', 'top-bar', __( 'Sticky on desktop', 'multimagazine' ) );
	}

	/**
	 * Registers the topbar height setting.
	 */
	public static function register_topbar_height() {
		global $multimagazine_customize;
		$multimagazine_customize->range_setting(
			'multi_topbar_height',
			'top-bar',
			20,
			100,
			1,
			__( 'Top bar height', 'multimagazine' ),
			__( 'Set the height of the top bar in pixels. Default is 40px.', 'multimagazine' )
		);
	}

	/**
	 * Registers the topbar bg color setting.
	 */
	public static function register_topbar_bg_color() {
		global $multimagazine_customize;
		$multimagazine_customize->color_alpha_setting( 'multi_topbar_bg_color', 'top-bar', __( 'Top bar background color', 'multimagazine' ), '', 'postMessage' );
	}

	/**
	 * Registers the topbar bg color sticky setting.
	 */
	public static function register_topbar_bg_color_sticky() {
		global $multimagazine_customize;
		$multimagazine_customize->color_alpha_setting( 'multi_topbar_bg_color_sticky', 'top-bar', __( 'Top bar background color (in sticky header)', 'multimagazine' ), __( 'Leave empty for no change', 'multimagazine' ), 'postMessage' );
	}

	/**
	 * Registers the topbar text color setting.
	 */
	public static function register_topbar_text_color() {
		global $multimagazine_customize;
		$multimagazine_customize->color_setting( 'multi_topbar_text_color', 'top-bar', __( 'Top bar text color', 'multimagazine' ), '', 'postMessage' );
	}

	/**
	 * Registers the topbar link color setting.
	 */
	public static function register_topbar_link_color() {
		global $multimagazine_customize;
		$multimagazine_customize->color_setting( 'multi_topbar_link_color', 'top-bar', __( 'Top bar link color', 'multimagazine' ), '', 'postMessage' );
	}

	/**
	 * Registers the topbar link hover color setting.
	 */
	public static function register_topbar_link_hover_color() {
		global $multimagazine_customize;
		$multimagazine_customize->color_setting( 'multi_topbar_link_hover_color', 'top-bar', __( 'Top bar link hover color', 'multimagazine' ), '', 'postMessage' );
	}

	/**
	 * Registers the top bar msg setting.
	 */
	public static function register_top_bar_msg() {
		global $multimagazine_customize;
		$multimagazine_customize->text_setting(
			'multi_top_bar_msg',
			'top-bar',
			__( 'Top bar message', 'multimagazine' ),
			'',
			array( 'Multimagazine_Sanitizer', 'simple_html' )
		);
	}

	/**
	 * Registers the top bar msg pos setting.
	 */
	public static function register_top_bar_msg_pos() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting(
			'multi_top_bar_msg_pos',
			'top-bar',
			array(
				'off'    => __( "Don't show", 'multimagazine' ),
				'left'   => __( 'Left', 'multimagazine' ),
				'center' => __( 'Center', 'multimagazine' ),
				'right'  => __( 'Right', 'multimagazine' ),
			),
			__( 'Top bar message position', 'multimagazine' )
		);
	}

	/**
	 * Registers the top bar menu pos setting.
	 */
	public static function register_top_bar_menu_pos() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting(
			'multi_top_bar_menu_pos',
			'top-bar',
			array(
				'off'    => __( "Don't show", 'multimagazine' ),
				'left'   => __( 'Left', 'multimagazine' ),
				'center' => __( 'Center', 'multimagazine' ),
				'right'  => __( 'Right', 'multimagazine' ),
			),
			__( 'Top bar menu position', 'multimagazine' )
		);
	}

	/**
	 * Registers the top bar social pos setting.
	 */
	public static function register_top_bar_social_pos() {
		global $multimagazine_customize;
		$multimagazine_customize->select_setting(
			'multi_top_bar_social_pos',
			'top-bar',
			array(
				'off'    => __( "Don't show", 'multimagazine' ),
				'left'   => __( 'Left', 'multimagazine' ),
				'center' => __( 'Center', 'multimagazine' ),
				'right'  => __( 'Right', 'multimagazine' ),
			),
			__( 'Top bar social links position', 'multimagazine' )
		);
	}

	/**
	 * Registers the topbar middle ratio setting.
	 */
	public static function register_topbar_middle_ratio() {
		global $multimagazine_customize;
		$multimagazine_customize->number_setting(
			'multi_topbar_middle_ratio',
			'top-bar',
			__( 'Top bar middle part width ratio', 'multimagazine' ),
			__( 'Set the width ratio of the middle part of the top bar. The remaining width is divided between the left and right parts. Default is 2, which means that the middle part is twice as wide as each of the side parts.', 'multimagazine' )
		);
	}
}

add_action( 'customize_register', array( 'Multimagazine_Customize_Top_Bar', 'register_section' ) );
add_action( 'multimagazine_customize_top_bar', array( 'Multimagazine_Customize_Top_Bar', 'register_show_topbar' ), 10 );
add_action( 'multimagazine_customize_top_bar', array( 'Multimagazine_Customize_Top_Bar', 'register_topbar_sticky_mobile' ), 15 );
add_action( 'multimagazine_customize_top_bar', array( 'Multimagazine_Customize_Top_Bar', 'register_topbar_sticky_desktop' ), 20 );
add_action( 'multimagazine_customize_top_bar', array( 'Multimagazine_Customize_Top_Bar', 'register_topbar_height' ), 25 );
add_action( 'multimagazine_customize_top_bar', array( 'Multimagazine_Customize_Top_Bar', 'register_topbar_bg_color' ), 30 );
add_action( 'multimagazine_customize_top_bar', array( 'Multimagazine_Customize_Top_Bar', 'register_topbar_bg_color_sticky' ), 35 );
add_action( 'multimagazine_customize_top_bar', array( 'Multimagazine_Customize_Top_Bar', 'register_topbar_text_color' ), 40 );
add_action( 'multimagazine_customize_top_bar', array( 'Multimagazine_Customize_Top_Bar', 'register_topbar_link_color' ), 45 );
add_action( 'multimagazine_customize_top_bar', array( 'Multimagazine_Customize_Top_Bar', 'register_topbar_link_hover_color' ), 50 );
add_action( 'multimagazine_customize_top_bar', array( 'Multimagazine_Customize_Top_Bar', 'register_top_bar_msg' ), 55 );
add_action( 'multimagazine_customize_top_bar', array( 'Multimagazine_Customize_Top_Bar', 'register_top_bar_msg_pos' ), 60 );
add_action( 'multimagazine_customize_top_bar', array( 'Multimagazine_Customize_Top_Bar', 'register_top_bar_menu_pos' ), 65 );
add_action( 'multimagazine_customize_top_bar', array( 'Multimagazine_Customize_Top_Bar', 'register_top_bar_social_pos' ), 70 );
add_action( 'multimagazine_customize_top_bar', array( 'Multimagazine_Customize_Top_Bar', 'register_topbar_middle_ratio' ), 75 );
