<?php
/**
 * Business Interface Hero Section 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_Hero' ) ) :
	/**
	 * Business Interface Page Title Settings section in Customizer.
	 */
	class Business_Interface_Customizer_Hero {

		/**
		 * 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 ) {

			// Hero Section.
			$options['section']['business_interface_section_hero'] = array(
				'title'    => esc_html__( 'Hero', 'business-interface' ),
				'priority' => 3,
			);

			// Hero enable.
			$options['setting']['business_interface_enable_hero'] = array(
				'transport'         => 'refresh',
				'sanitize_callback' => 'business_interface_sanitize_toggle',
				'control'           => array(
					'type'    => 'business-interface-toggle',
					'section' => 'business_interface_section_hero',
					'label'   => esc_html__( 'Enable Hero Section', 'business-interface' ),
				),
			);

			// Visibility.
			$options['setting']['business_interface_hero_visibility'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_select',
				'control'           => array(
					'type'        => 'business-interface-select',
					'section'     => 'business_interface_section_hero',
					'label'       => esc_html__( 'Device Visibility', 'business-interface' ),
					'description' => esc_html__( 'Devices where the Hero is displayed.', 'business-interface' ),
					'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_enable_hero',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Hero display on.
			$options['setting']['business_interface_hero_enable_on'] = array(
				'transport'         => 'refresh',
				'sanitize_callback' => 'business_interface_sanitize_checkbox_group',
				'control'           => array(
					'type'        => 'business-interface-checkbox-group',
					'label'       => esc_html__( 'Enable On: ', 'business-interface' ),
					'description' => esc_html__( 'Choose on which pages you want to enable Hero. ', 'business-interface' ),
					'section'     => 'business_interface_section_hero',
					'choices'     => array(
						'home'       => array(
							'title' => esc_html__( 'Home Page', 'business-interface' ),
						),
						'posts_page' => array(
							'title' => esc_html__( 'Blog / Posts Page', 'business-interface' ),
						),
					),
					'required'    => array(
						array(
							'control'  => 'business_interface_enable_hero',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Hover Slider heading.
			$options['setting']['business_interface_hero_hover_slider'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_toggle',
				'control'           => array(
					'type'     => 'business-interface-heading',
					'section'  => 'business_interface_section_hero',
					'label'    => esc_html__( 'Style', 'business-interface' ),
					'required' => array(
						array(
							'control'  => 'business_interface_enable_hero',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_hero_type',
							'value'    => 'hover-slider',
							'operator' => '==',
						),
					),
				),
			);

			// Hover Slider container width.
			$options['setting']['business_interface_hero_hover_slider_container'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_select',
				'control'           => array(
					'type'        => 'business-interface-select',
					'section'     => 'business_interface_section_hero',
					'label'       => esc_html__( 'Width', 'business-interface' ),
					'description' => esc_html__( 'Stretch the container to full width, or match your site&rsquo;s content width.', 'business-interface' ),
					'choices'     => array(
						'content-width' => esc_html__( 'Content Width', 'business-interface' ),
						'full-width'    => esc_html__( 'Full Width', 'business-interface' ),
					),
					'required'    => array(
						array(
							'control'  => 'business_interface_enable_hero',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_hero_hover_slider',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_hero_type',
							'value'    => 'hover-slider',
							'operator' => '==',
						),
					),
				),
			);

			// Hover Slider height.
			$options['setting']['business_interface_hero_hover_slider_height'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_range',
				'control'           => array(
					'type'        => 'business-interface-range',
					'section'     => 'business_interface_section_hero',
					'label'       => esc_html__( 'Height', 'business-interface' ),
					'description' => esc_html__( 'Set the height of the container.', 'business-interface' ),
					'min'         => 350,
					'max'         => 1000,
					'step'        => 1,
					'unit'        => 'px',
					'required'    => array(
						array(
							'control'  => 'business_interface_enable_hero',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_hero_hover_slider',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_hero_type',
							'value'    => 'hover-slider',
							'operator' => '==',
						),
					),
				),
			);

			// Hover Slider overlay.
			$options['setting']['business_interface_hero_hover_slider_overlay'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_select',
				'control'           => array(
					'type'        => 'business-interface-select',
					'section'     => 'business_interface_section_hero',
					'label'       => esc_html__( 'Overlay', 'business-interface' ),
					'description' => esc_html__( 'Choose hero overlay style.', 'business-interface' ),
					'choices'     => array(
						'none' => esc_html__( 'None', 'business-interface' ),
						'1'    => esc_html__( 'Overlay 1', 'business-interface' ),
						'2'    => esc_html__( 'Overlay 2', 'business-interface' ),
					),
					'required'    => array(
						array(
							'control'  => 'business_interface_enable_hero',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_hero_hover_slider',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_hero_type',
							'value'    => 'hover-slider',
							'operator' => '==',
						),
					),
				),
			);

			// Hover Slider Elements.
			$options['setting']['business_interface_hero_hover_slider_elements'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_sortable',
				'control'           => array(
					'type'        => 'business-interface-sortable',
					'section'     => 'business_interface_section_hero',
					'label'       => esc_html__( 'Post Elements', 'business-interface' ),
					'description' => esc_html__( 'Set order and visibility for post elements.', 'business-interface' ),
					'sortable'    => false,
					'choices'     => array(
						'category'  => esc_html__( 'Categories', 'business-interface' ),
						'meta'      => esc_html__( 'Post Details', 'business-interface' ),
						'read_more' => esc_html__( 'Continue Reading', 'business-interface' ),
					),
					'required'    => array(
						array(
							'control'  => 'business_interface_enable_hero',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_hero_hover_slider',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_hero_type',
							'value'    => 'hover-slider',
							'operator' => '==',
						),
					),
				),
				'partial'           => array(
					'selector'            => '#hero',
					'render_callback'     => 'business_interface_hero',
					'container_inclusive' => true,
					'fallback_refresh'    => true,
				),
			);

			// Post Settings heading.
			$options['setting']['business_interface_hero_hover_slider_posts'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_toggle',
				'control'           => array(
					'type'     => 'business-interface-heading',
					'section'  => 'business_interface_section_hero',
					'label'    => esc_html__( 'Post Settings', 'business-interface' ),
					'required' => array(
						array(
							'control'  => 'business_interface_enable_hero',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_hero_type',
							'value'    => 'hover-slider',
							'operator' => '==',
						),
					),
				),
			);

			// Post count.
			$options['setting']['business_interface_hero_hover_slider_post_number'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_range',
				'control'           => array(
					'type'        => 'business-interface-range',
					'section'     => 'business_interface_section_hero',
					'label'       => esc_html__( 'Post Number', 'business-interface' ),
					'description' => esc_html__( 'Set the number of visible posts.', 'business-interface' ),
					'min'         => 1,
					'max'         => 4,
					'step'        => 1,
					'unit'        => '',
					'required'    => array(
						array(
							'control'  => 'business_interface_enable_hero',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_hero_hover_slider_posts',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_hero_type',
							'value'    => 'hover-slider',
							'operator' => '==',
						),
					),
				),
				'partial'           => array(
					'selector'            => '#hero',
					'render_callback'     => 'business_interface_hero',
					'container_inclusive' => true,
					'fallback_refresh'    => true,
				),
			);

			// Post category.
			$options['setting']['business_interface_hero_hover_slider_category'] = array(
				'transport'         => 'refresh',
				'sanitize_callback' => 'business_interface_sanitize_select',
				'control'           => array(
					'type'        => 'business-interface-select',
					'section'     => 'business_interface_section_hero',
					'label'       => esc_html__( 'Category', 'business-interface' ),
					'description' => esc_html__( 'Display posts from selected category only. Leave empty to include all.', 'business-interface' ),
					'is_select2'  => true,
					'data_source' => 'category',
					'multiple'    => true,
					'required'    => array(
						array(
							'control'  => 'business_interface_enable_hero',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_hero_hover_slider_posts',
							'value'    => true,
							'operator' => '==',
						),
						array(
							'control'  => 'business_interface_hero_type',
							'value'    => 'hover-slider',
							'operator' => '==',
						),
					),
				),
			);

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