<?php
function storex_general_setting( $wp_customize ) {
	$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';
	$wp_customize->add_panel(
		'storex_general', array(
			'priority' => 31,
			'title' => esc_html__( 'General', 'storex' ),
		)
	);	
	
	/*=========================================
	Breadcrumb  Section
	=========================================*/
	$wp_customize->add_section(
		'storex_breadcrumb_setting', array(
			'title' => esc_html__( 'Breadcrumb Section', 'storex' ),
			'priority' => 1,
			'panel' => 'storex_general',
		)
	);
	
	// Settings
	$wp_customize->add_setting(
		'storex_breadcrumb_settings'
		,array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'storex_sanitize_text',
			'priority' => 1,
		)
	);

	$wp_customize->add_control(
		'storex_breadcrumb_settings',
		array(
			'type' => 'hidden',
			'label' => __('Settings','storex'),
			'section' => 'storex_breadcrumb_setting',
		)
	);
	
	// Breadcrumb Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'storex_hs_breadcrumb' , 
		array(
			'default' => esc_html__( '1', 'storex' ),
			'sanitize_callback' => 'storex_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'transport'         => $selective_refresh,
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
		'storex_hs_breadcrumb', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'storex' ),
			'section'     => 'storex_breadcrumb_setting',
			'settings'    => 'storex_hs_breadcrumb',
			'type'        => 'checkbox'
		) 
	);
	
	// Breadcrumb Content Section // 
	if ( class_exists( 'Burger_Customizer_Range_Control' ) ) {
		$wp_customize->add_setting(
			'storex_breadcrumb_contents'
			,array(
				'capability'     	=> 'edit_theme_options',
				'sanitize_callback' => 'storex_sanitize_text',
				'priority' => 5,
			)
		);

		$wp_customize->add_control(
			'storex_breadcrumb_contents',
			array(
				'type' => 'hidden',
				'label' => __('Content','storex'),
				'section' => 'storex_breadcrumb_setting',
			)
		);
		
	// Content size // 
		$wp_customize->add_setting(
			'storex_breadcrumb_min_height',
			array(
				'default'           => esc_html__( '236', 'storex' ),
				'capability'     	=> 'edit_theme_options',
				'sanitize_callback' => 'storex_sanitize_range_value',
				'transport'         => 'postMessage',
				'priority' => 6,
			)
		);
		$wp_customize->add_control( 
			new Burger_Customizer_Range_Control( $wp_customize, 'storex_breadcrumb_min_height', 
				array(
					'label'      => __( 'Min Height', 'storex'),
					'section'  => 'storex_breadcrumb_setting',
					'input_attrs' => array(
						'min'    => 0,
						'max'    => 1000,
						'step'   => 1,
					//'suffix' => 'px', //optional suffix
					),
				) ) 
		);
	}	
	
	// Background // 
	$wp_customize->add_setting(
		'storex_breadcrumb_bg_head'
		,array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'storex_sanitize_text',
			'priority' => 9,
		)
	);

	$wp_customize->add_control(
		'storex_breadcrumb_bg_head',
		array(
			'type' => 'hidden',
			'label' => __('Background','storex'),
			'section' => 'storex_breadcrumb_setting',
		)
	);
	
	// Background Image // 
	$wp_customize->add_setting( 
		'storex_breadcrumb_bg_img' , 
		array(
			'default' 			=> esc_url(get_template_directory_uri() .'/assets/images/bg/breadcrumbg.jpg'),
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'storex_sanitize_url',	
			'priority' => 10,
		) 
	);
	
	$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize , 'storex_breadcrumb_bg_img' ,
		array(
			'label'          => esc_html__( 'Background Image', 'storex'),
			'section'        => 'storex_breadcrumb_setting',
		) 
	));
	
	// Background Attachment // 
	$wp_customize->add_setting( 
		'storex_breadcrumb_back_attach' , 
		array(
			'default'       => esc_html__( 'scroll', 'storex' ),
			'capability'    => 'edit_theme_options',
			'sanitize_callback' => 'storex_sanitize_select',
			'priority'  => 10,
		) 
	);
	
	$wp_customize->add_control(
		'storex_breadcrumb_back_attach' , 
		array(
			'label'          => __( 'Background Attachment', 'storex' ),
			'section'        => 'storex_breadcrumb_setting',
			'type'           => 'select',
			'choices'        => 
			array(
				'inherit' => __( 'Inherit', 'storex' ),
				'scroll' => __( 'Scroll', 'storex' ),
				'fixed'   => __( 'Fixed', 'storex' )
			) 
		) 
	);
	
	// Image Opacity // 
	if ( class_exists( 'Burger_Customizer_Range_Control' ) ) {
		$wp_customize->add_setting(
			'storex_breadcrumb_bg_img_opacity',
			array(
				'default'    => esc_html__( '0.75', 'storex' ),
				'capability'     	=> 'edit_theme_options',
				'sanitize_callback' => 'storex_sanitize_range_value',
				'priority'  => 11,
			)
		);
		$wp_customize->add_control( 
			new Burger_Customizer_Range_Control( $wp_customize, 'storex_breadcrumb_bg_img_opacity', 
				array(
					'label'      => __( 'Opacity', 'storex'),
					'section'  => 'storex_breadcrumb_setting',
					'settings' => 'storex_breadcrumb_bg_img_opacity',
					'media_query'   => false,
					'input_attr'    => array(
						'desktop' => array(
							'min'           => 0,
							'max'           => 1,
							'step'          => 0.1,
							'default_value' => 0.6,
						),
					),
				) ) 
		);
	}
}

add_action( 'customize_register', 'storex_general_setting' );

// breadcrumb selective refresh
function storex_breadcrumb_section_partials( $wp_customize ){

	// hs_breadcrumb
	$wp_customize->selective_refresh->add_partial(
		'hs_breadcrumb', array(
			'selector' => '#breadcrumb-section',
			'container_inclusive' => true,
			'render_callback' => 'storex_breadcrumb_setting',
			'fallback_refresh' => true,
		)
	);	
	
}
add_action( 'customize_register', 'storex_breadcrumb_section_partials' );