<?php
/**
 * Business Interface Top Bar Settings 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_Top_Bar' ) ) :
	/**
	 * Business Interface Top Bar Settings section in Customizer.
	 */
	class Business_Interface_Customizer_Top_Bar {

		/**
		 * 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_top_bar'] = array(
				'title'    => esc_html__( 'Top Bar', 'business-interface' ),
				'panel'    => 'business_interface_panel_header',
				'priority' => 10,
			);

			// Enable Top Bar.
			$options['setting']['business_interface_top_bar_enable'] = array(
				'transport'         => 'refresh',
				'sanitize_callback' => 'business_interface_sanitize_toggle',
				'control'           => array(
					'type'        => 'business-interface-toggle',
					'label'       => esc_html__( 'Enable Top Bar', 'business-interface' ),
					'description' => esc_html__( 'Top Bar is a section with widgets located above Main Header area.', 'business-interface' ),
					'section'     => 'business_interface_section_top_bar',
				),
			);

			// Top Bar container width.
			$options['setting']['business_interface_top_bar_container_width'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_select',
				'control'           => array(
					'type'        => 'business-interface-select',
					'label'       => esc_html__( 'Top Bar Width', 'business-interface' ),
					'description' => esc_html__( 'Stretch the Top Bar container to full width, or match your site&rsquo;s content width.', 'business-interface' ),
					'section'     => 'business_interface_section_top_bar',
					'choices'     => array(
						'content-width' => esc_html__( 'Content Width', 'business-interface' ),
						'full-width'    => esc_html__( 'Full Width', 'business-interface' ),
					),
					'required'    => array(
						array(
							'control'  => 'business_interface_top_bar_enable',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Top Bar visibility.
			$options['setting']['business_interface_top_bar_visibility'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_select',
				'control'           => array(
					'type'        => 'business-interface-select',
					'label'       => esc_html__( 'Device Visibility', 'business-interface' ),
					'description' => esc_html__( 'Devices where the Top Bar is displayed.', 'business-interface' ),
					'section'     => 'business_interface_section_top_bar',
					'choices'     => array(
						'all'                => esc_html__( 'Show on All Devices', 'business-interface' ),
						'hide-mobile'        => esc_html__( 'Hide on Mobile', 'business-interface' ),
						'hide-tablet'        => esc_html__( 'Hide on Tablet', 'business-interface' ),
						'hide-mobile-tablet' => esc_html__( 'Hide on Mobile and Tablet', 'business-interface' ),
					),
					'required'    => array(
						array(
							'control'  => 'business_interface_top_bar_enable',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Top Bar widgets heading.
			$options['setting']['business_interface_top_bar_heading_widgets'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_toggle',
				'control'           => array(
					'type'        => 'business-interface-heading',
					'label'       => esc_html__( 'Top Bar Widgets', 'business-interface' ),
					'description' => esc_html__( 'Click the Add Widget button to add available widgets to your Top Bar.', 'business-interface' ),
					'section'     => 'business_interface_section_top_bar',
					'required'    => array(
						array(
							'control'  => 'business_interface_top_bar_enable',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Top Bar widgets.
			$options['setting']['business_interface_top_bar_widgets'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_widget',
				'control'           => array(
					'type'       => 'business-interface-widget',
					'label'      => esc_html__( 'Top Bar Widgets', 'business-interface' ),
					'section'    => 'business_interface_section_top_bar',
					'widgets'    => array(
						'text'    => array(
							'max_uses' => 3,
						),
						'nav'     => array(
							'max_uses' => 1,
						),
						'socials' => array(
							'max_uses' => 1,
							'styles'   => array(
								'minimal' => esc_html__( 'Minimal', 'business-interface' ),
								'rounded' => esc_html__( 'Rounded', 'business-interface' ),
							),
						),
					),
					'locations'  => array(
						'left'  => esc_html__( 'Left', 'business-interface' ),
						'right' => esc_html__( 'Right', 'business-interface' ),
					),
					'visibility' => array(
						'all'                => esc_html__( 'Show on All Devices', 'business-interface' ),
						'hide-mobile'        => esc_html__( 'Hide on Mobile', 'business-interface' ),
						'hide-tablet'        => esc_html__( 'Hide on Tablet', 'business-interface' ),
						'hide-mobile-tablet' => esc_html__( 'Hide on Mobile and Tablet', 'business-interface' ),
					),
					'required'   => array(
						array(
							'control'  => 'business_interface_top_bar_heading_widgets',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_top_bar_enable',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
				'partial'           => array(
					'selector'            => '#business-interface-topbar',
					'render_callback'     => 'business_interface_topbar_output',
					'container_inclusive' => true,
					'fallback_refresh'    => true,
				),
			);

			// Top Bar widget separator.
			$options['setting']['business_interface_top_bar_widgets_separator'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_select',
				'control'           => array(
					'type'        => 'business-interface-select',
					'label'       => esc_html__( 'Widgets Separator', 'business-interface' ),
					'description' => esc_html__( 'Display a separator line between widgets.', 'business-interface' ),
					'section'     => 'business_interface_section_top_bar',
					'choices'     => array(
						'none'    => esc_html__( 'None', 'business-interface' ),
						'regular' => esc_html__( 'Regular', 'business-interface' ),
						'slanted' => esc_html__( 'Slanted', 'business-interface' ),
					),
					'required'    => array(
						array(
							'control'  => 'business_interface_top_bar_heading_widgets',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_top_bar_enable',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Top Bar design options heading.
			$options['setting']['business_interface_top_bar_heading_design_options'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_toggle',
				'control'           => array(
					'type'     => 'business-interface-heading',
					'label'    => esc_html__( 'Design Options', 'business-interface' ),
					'section'  => 'business_interface_section_top_bar',
					'required' => array(
						array(
							'control'  => 'business_interface_top_bar_enable',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Top Bar Background.
			$options['setting']['business_interface_top_bar_background'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_design_options',
				'control'           => array(
					'type'     => 'business-interface-design-options',
					'label'    => esc_html__( 'Background', 'business-interface' ),
					'section'  => 'business_interface_section_top_bar',
					'display'  => array(
						'background' => array(
							'color'    => esc_html__( 'Solid Color', 'business-interface' ),
							'gradient' => esc_html__( 'Gradient', 'business-interface' ),
						),
					),
					'required' => array(
						array(
							'control'  => 'business_interface_top_bar_enable',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_top_bar_heading_design_options',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Top Bar Text Color.
			$options['setting']['business_interface_top_bar_text_color'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_design_options',
				'control'           => array(
					'type'     => 'business-interface-design-options',
					'label'    => esc_html__( 'Font Color', 'business-interface' ),
					'section'  => 'business_interface_section_top_bar',
					'display'  => array(
						'color' => array(
							'text-color'       => esc_html__( 'Text Color', 'business-interface' ),
							'link-color'       => esc_html__( 'Link Color', 'business-interface' ),
							'link-hover-color' => esc_html__( 'Link Hover Color', 'business-interface' ),
						),
					),
					'required' => array(
						array(
							'control'  => 'business_interface_top_bar_enable',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_top_bar_heading_design_options',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Top Bar Border.
			$options['setting']['business_interface_top_bar_border'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_design_options',
				'control'           => array(
					'type'     => 'business-interface-design-options',
					'label'    => esc_html__( 'Border', 'business-interface' ),
					'section'  => 'business_interface_section_top_bar',
					'display'  => array(
						'border' => array(
							'style'     => esc_html__( 'Style', 'business-interface' ),
							'color'     => esc_html__( 'Color', 'business-interface' ),
							'width'     => esc_html__( 'Width (px)', 'business-interface' ),
							'positions' => array(
								'top'    => esc_html__( 'Top', 'business-interface' ),
								'bottom' => esc_html__( 'Bottom', 'business-interface' ),
							),
							'separator' => esc_html__( 'Separator Color', 'business-interface' ),
						),
					),
					'required' => array(
						array(
							'control'  => 'business_interface_top_bar_enable',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_top_bar_heading_design_options',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			return $options;
		}
	}
endif;
new Business_Interface_Customizer_Top_Bar();
