<?php
/**
 * Business Interface Transparent Header 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_Transparent_Header' ) ) :
	/**
	 * Business Interface Main Transparent section in Customizer.
	 */
	class Business_Interface_Customizer_Transparent_Header {

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

			// Transparent Header Section.
			$options['section']['business_interface_section_transparent_header'] = array(
				'title'    => esc_html__( 'Transparent Header', 'business-interface' ),
				'panel'    => 'business_interface_panel_header',
				'priority' => 80,
			);

			// Enable Transparent Header.
			$options['setting']['business_interface_tsp_header'] = array(
				'transport'         => 'refresh',
				'sanitize_callback' => 'business_interface_sanitize_toggle',
				'control'           => array(
					'type'    => 'business-interface-toggle',
					'label'   => esc_html__( 'Enable Globally', 'business-interface' ),
					'section' => 'business_interface_section_transparent_header',
				),
			);

			// Disable choices.
			$disable_choices = array(
				'404' => array(
					'title' => esc_html__( '404 page', 'business-interface' ),
				),
				'posts_page' => array(
					'title' => esc_html__( 'Blog / Posts page', 'business-interface' ),
				),
				'archive' => array(
					'title' => esc_html__( 'Archive pages', 'business-interface' ),
				),
				'search' => array(
					'title' => esc_html__( 'Search pages', 'business-interface' ),
				),
				'post' => array(
					'title' => esc_html__( 'Posts', 'business-interface' ),
				),
				'page' => array(
					'title' => esc_html__( 'Pages', 'business-interface' ),
				),
			);

			// Get additionally registered post types.
			$post_types = get_post_types(
				array(
					'public'   => true,
					'_builtin' => false,
				),
				'objects'
			);

			if ( is_array( $post_types ) && ! empty( $post_types ) ) {
				foreach ( $post_types as $slug => $post_type ) {
					$disable_choices[ $slug ] = array(
						'title' => $post_type->label,
					);
				}
			}

			// Transparent header display on.
			$options['setting']['business_interface_tsp_header_disable_on'] = array(
				'transport'         => 'refresh',
				'sanitize_callback' => 'business_interface_sanitize_checkbox_group',
				'control'           => array(
					'type'        => 'business-interface-checkbox-group',
					'label'       => esc_html__( 'Disable On: ', 'business-interface' ),
					'description' => esc_html__( 'Choose on which pages you want to disable Transparent Header. ', 'business-interface' ),
					'section'     => 'business_interface_section_transparent_header',
					'choices'     => $disable_choices,
					'required'    => array(
						array(
							'control'  => 'business_interface_tsp_header',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Logo Settings Heading.
			$options['setting']['business_interface_tsp_logo_heading'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_toggle',
				'control'           => array(
					'type'     => 'business-interface-heading',
					'label'    => esc_html__( 'Logo Settings', 'business-interface' ),
					'section'  => 'business_interface_section_transparent_header',
				),
			);

			// Logo.
			$options['setting']['business_interface_tsp_logo'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_background',
				'control'           => array(
					'type'        => 'business-interface-background',
					'section'     => 'business_interface_section_transparent_header',
					'label'       => esc_html__( 'Alternative Logo', 'business-interface' ),
					'description' => esc_html__( 'Upload a different logo to be used with Transparent Header.', 'business-interface' ),
					'advanced'    => false,
					'strings'     => array(
						'select_image' => __( 'Select logo', 'business-interface' ),
						'use_image'    => __( 'Select', 'business-interface' ),
					),
					'required'    => array(
						array(
							'control'  => 'business_interface_tsp_logo_heading',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
				'partial'           => array(
					'selector'            => '.business-interface-logo',
					'render_callback'     => 'business_interface_logo',
					'container_inclusive' => false,
					'fallback_refresh'    => true,
				),
			);

			// Logo Retina.
			$options['setting']['business_interface_tsp_logo_retina'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_background',
				'control'           => array(
					'type'        => 'business-interface-background',
					'section'     => 'business_interface_section_transparent_header',
					'label'       => esc_html__( 'Alternative Logo - Retina', 'business-interface' ),
					'description' => esc_html__( 'Upload exactly 2x the size of your alternative logo to make your logo crisp on HiDPI screens. This options is not required if logo above is in SVG format.', 'business-interface' ),
					'advanced'    => false,
					'strings'     => array(
						'select_image' => __( 'Select logo', 'business-interface' ),
						'use_image'    => __( 'Select', 'business-interface' ),
					),
					'required'    => array(
						array(
							'control'  => 'business_interface_tsp_logo_heading',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
				'partial'           => array(
					'selector'            => '.business-interface-logo',
					'render_callback'     => 'business_interface_logo',
					'container_inclusive' => false,
					'fallback_refresh'    => true,
				),
			);

			// Logo Max Height.
			$options['setting']['business_interface_tsp_logo_max_height'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_responsive',
				'control'           => array(
					'type'        => 'business-interface-range',
					'label'       => esc_html__( 'Logo Height', 'business-interface' ),
					'description' => esc_html__( 'Maximum logo image height on transparent header.', 'business-interface' ),
					'section'     => 'business_interface_section_transparent_header',
					'min'         => 0,
					'max'         => 1000,
					'step'        => 10,
					'unit'        => 'px',
					'responsive'  => true,
					'required'    => array(
						array(
							'control'  => 'business_interface_tsp_logo_heading',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Logo margin.
			$options['setting']['business_interface_tsp_logo_margin'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_responsive',
				'control'           => array(
					'type'        => 'business-interface-spacing',
					'label'       => esc_html__( 'Logo Margin', 'business-interface' ),
					'description' => esc_html__( 'Specify spacing around logo on transparent header. Negative values are allowed. Leave empty to inherit from Logos & Site Title » Logo Margin.', 'business-interface' ),
					'section'     => 'business_interface_section_transparent_header',
					'choices'     => array(
						'top'    => esc_html__( 'Top', 'business-interface' ),
						'right'  => esc_html__( 'Right', 'business-interface' ),
						'bottom' => esc_html__( 'Bottom', 'business-interface' ),
						'left'   => esc_html__( 'Left', 'business-interface' ),
					),
					'responsive'  => true,
					'unit'        => array(
						'px',
					),
					'required'    => array(
						array(
							'control'  => 'business_interface_tsp_logo_heading',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Custom Colors Heading.
			$options['setting']['business_interface_tsp_colors_heading'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_toggle',
				'control'           => array(
					'type'     => 'business-interface-heading',
					'label'    => esc_html__( 'Main Header Colors', 'business-interface' ),
					'section'  => 'business_interface_section_transparent_header',
				),
			);

			// Background.
			$options['setting']['business_interface_tsp_header_background'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_design_options',
				'control'           => array(
					'type'     => 'business-interface-design-options',
					'section'  => 'business_interface_section_transparent_header',
					'label'    => esc_html__( 'Background', 'business-interface' ),
					'space'    => true,
					'display'  => array(
						'background' => array(
							'color' => esc_html__( 'Solid Color', 'business-interface' ),
						),
					),
					'required' => array(
						array(
							'control'  => 'business_interface_tsp_colors_heading',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Text Color.
			$options['setting']['business_interface_tsp_header_font_color'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_design_options',
				'control'           => array(
					'type'     => 'business-interface-design-options',
					'section'  => 'business_interface_section_transparent_header',
					'label'    => esc_html__( 'Font Color', 'business-interface' ),
					'space'    => true,
					'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_tsp_colors_heading',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

			// Border.
			$options['setting']['business_interface_tsp_header_border'] = array(
				'transport'         => 'postMessage',
				'sanitize_callback' => 'business_interface_sanitize_design_options',
				'control'           => array(
					'type'     => 'business-interface-design-options',
					'section'  => 'business_interface_section_transparent_header',
					'label'    => esc_html__( 'Border', 'business-interface' ),
					'space'    => true,
					'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_tsp_colors_heading',
							'value'    => true,
							'operator' => '==',
						),
					),
				),
			);

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