<?php
/**
 * Business Interface Sidebar section in Customizer.
 *
 * @package     Business Interface
 * @author  WPInterface Team
 * @since   1.0.0
 */

/**
 * Do not allow direct script access.
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'Business_Interface_Customizer_Sidebar' ) ) :

	/**
	 * Business Interface Sidebar section in Customizer.
	 */
	class Business_Interface_Customizer_Sidebar {

		/**
		 * Primary class constructor.
		 *
		 * @since 1.0.0
		 */
		public function __construct() {

			/**
			 * Registers our custom options in Customizer.
			 */
			add_filter( 'business_interface_customizer_options', array( $this, 'register_options' ) );
		}

		/**
		 * Registers our custom options in Customizer.
		 *
		 * @since 1.0.0
		 * @param array $options Array of customizer options.
		 */
		public function register_options( $options ) {

			// Section.
			$options['section']['business_interface_section_sidebar'] = array(
				'title'    => esc_html__( 'Sidebar', 'business-interface' ),
				'priority' => 4,
			);

			// Default sidebar position.
			$options['setting']['business_interface_sidebar_position'] = array(
				'transport'         => 'refresh',
				'sanitize_callback' => 'business_interface_sanitize_select',
				'control'           => array(
					'type'        => 'business-interface-select',
					'section'     => 'business_interface_section_sidebar',
					'label'       => esc_html__( 'Default Position', 'business-interface' ),
					'description' => esc_html__( 'Choose default sidebar position layout. You can change this setting per page via metabox settings.', 'business-interface' ),
					'choices'     => array(
						'no-sidebar'    => esc_html__( 'No Sidebar', 'business-interface' ),
						'left-sidebar'  => esc_html__( 'Left Sidebar', 'business-interface' ),
						'right-sidebar' => esc_html__( 'Right Sidebar', 'business-interface' ),
					),
				),
			);

			// Single post sidebar position.
			$options['setting']['business_interface_single_post_sidebar_position'] = array(
				'transport'         => 'refresh',
				'sanitize_callback' => 'business_interface_sanitize_select',
				'control'           => array(
					'type'        => 'business-interface-select',
					'label'       => esc_html__( 'Single Post', 'business-interface' ),
					'description' => esc_html__( 'Choose default sidebar position layout for single posts. You can change this setting per post via metabox settings.', 'business-interface' ),
					'section'     => 'business_interface_section_sidebar',
					'choices'     => array(
						'default'       => esc_html__( 'Default', 'business-interface' ),
						'no-sidebar'    => esc_html__( 'No Sidebar', 'business-interface' ),
						'left-sidebar'  => esc_html__( 'Left Sidebar', 'business-interface' ),
						'right-sidebar' => esc_html__( 'Right Sidebar', 'business-interface' ),
					),
				),
			);

			// Single page sidebar position.
			$options['setting']['business_interface_single_page_sidebar_position'] = array(
				'transport'         => 'refresh',
				'sanitize_callback' => 'business_interface_sanitize_select',
				'control'           => array(
					'type'        => 'business-interface-select',
					'label'       => esc_html__( 'Page', 'business-interface' ),
					'description' => esc_html__( 'Choose default sidebar position layout for pages. You can change this setting per page via metabox settings.', 'business-interface' ),
					'section'     => 'business_interface_section_sidebar',
					'choices'     => array(
						'default'       => esc_html__( 'Default', 'business-interface' ),
						'no-sidebar'    => esc_html__( 'No Sidebar', 'business-interface' ),
						'left-sidebar'  => esc_html__( 'Left Sidebar', 'business-interface' ),
						'right-sidebar' => esc_html__( 'Right Sidebar', 'business-interface' ),
					),
				),
			);

			// Archive sidebar position.
			$options['setting']['business_interface_archive_sidebar_position'] = array(
				'transport'         => 'refresh',
				'sanitize_callback' => 'business_interface_sanitize_select',
				'control'           => array(
					'type'        => 'business-interface-select',
					'label'       => esc_html__( 'Archives & Search', 'business-interface' ),
					'description' => esc_html__( 'Choose default sidebar position layout for archives and search results.', 'business-interface' ),
					'section'     => 'business_interface_section_sidebar',
					'choices'     => array(
						'default'       => esc_html__( 'Default', 'business-interface' ),
						'no-sidebar'    => esc_html__( 'No Sidebar', 'business-interface' ),
						'left-sidebar'  => esc_html__( 'Left Sidebar', 'business-interface' ),
						'right-sidebar' => esc_html__( 'Right Sidebar', 'business-interface' ),
					),
				),
			);

			// Sidebar options heading.
			$options['setting']['business_interface_sidebar_options_heading'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_toggle',
				'control'           => array(
					'type'    => 'business-interface-heading',
					'label'   => esc_html__( 'Options', 'business-interface' ),
					'section' => 'business_interface_section_sidebar',
				),
			);

			// Sidebar style.
			$options['setting']['business_interface_sidebar_style'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_select',
				'control'           => array(
					'type'        => 'business-interface-select',
					'section'     => 'business_interface_section_sidebar',
					'label'       => esc_html__( 'Sidebar Style', 'business-interface' ),
					'description' => esc_html__( 'Choose sidebar style.', 'business-interface' ),
					'choices'     => array(
						'1' => esc_html__( 'Minimal', 'business-interface' ),
						'2' => esc_html__( 'Title Focus', 'business-interface' ),
						'3' => esc_html__( 'Widgets Separated', 'business-interface' ),
					),
					'required'    => array(
						array(
							'control'  => 'business_interface_sidebar_options_heading',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Sidebar width.
			$options['setting']['business_interface_sidebar_width'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_range',
				'control'           => array(
					'type'        => 'business-interface-range',
					'section'     => 'business_interface_section_sidebar',
					'label'       => esc_html__( 'Sidebar Width', 'business-interface' ),
					'description' => esc_html__( 'Change your sidebar width.', 'business-interface' ),
					'min'         => 15,
					'max'         => 50,
					'step'        => 1,
					'unit'        => '%',
					'required'    => array(
						array(
							'control'  => 'business_interface_sidebar_options_heading',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Sticky sidebar.
			$options['setting']['business_interface_sidebar_sticky'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_select',
				'control'           => array(
					'type'        => 'business-interface-select',
					'section'     => 'business_interface_section_sidebar',
					'label'       => esc_html__( 'Sticky Sidebar', 'business-interface' ),
					'description' => esc_html__( 'Stick sidebar when scrolling.', 'business-interface' ),
					'choices'     => array(
						''            => esc_html__( 'Disable', 'business-interface' ),
						'sidebar'     => esc_html__( 'Stick first widget', 'business-interface' ),
						'last-widget' => esc_html__( 'Stick last widget', 'business-interface' ),
					),
					'required'    => array(
						array(
							'control'  => 'business_interface_sidebar_options_heading',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Sidebar mobile position.
			$options['setting']['business_interface_sidebar_responsive_position'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_select',
				'control'           => array(
					'type'        => 'business-interface-select',
					'section'     => 'business_interface_section_sidebar',
					'label'       => esc_html__( 'Responsive Sidebar Position', 'business-interface' ),
					'description' => esc_html__( 'Control sidebar position on smaller screens.', 'business-interface' ),
					'choices'     => array(
						'hide'           => esc_html__( 'Hide', 'business-interface' ),
						'before-content' => esc_html__( 'Before Content', 'business-interface' ),
						'after-content'  => esc_html__( 'After Content', 'business-interface' ),
					),
					'required'    => array(
						array(
							'control'  => 'business_interface_sidebar_options_heading',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Sidebar typography heading.
			$options['setting']['business_interface_typography_sidebar_heading'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_toggle',
				'control'           => array(
					'type'    => 'business-interface-heading',
					'label'   => esc_html__( 'Typography', 'business-interface' ),
					'section' => 'business_interface_section_sidebar',
				),
			);

			// Sidebar widget heading.
			$options['setting']['business_interface_sidebar_widget_title_font_size'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_responsive',
				'control'           => array(
					'type'        => 'business-interface-range',
					'label'       => esc_html__( 'Widget Title Font Size', 'business-interface' ),
					'description' => esc_html__( 'Specify sidebar widget title font size.', 'business-interface' ),
					'section'     => 'business_interface_section_sidebar',
					'responsive'  => true,
					'unit'        => array(
						array(
							'id'   => 'px',
							'name' => 'px',
							'min'  => 8,
							'max'  => 90,
							'step' => 1,
						),
						array(
							'id'   => 'em',
							'name' => 'em',
							'min'  => 0.5,
							'max'  => 5,
							'step' => 0.01,
						),
						array(
							'id'   => 'rem',
							'name' => 'rem',
							'min'  => 0.5,
							'max'  => 5,
							'step' => 0.01,
						),
					),
					'required'    => array(
						array(
							'control'  => 'business_interface_typography_sidebar_heading',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			return $options;
		}
	}
endif;

new Business_Interface_Customizer_Sidebar();
