<?php
function glides_sidebar_settings( $wp_customize ) {
$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';	

	/*=========================================
	Glides Sidebar
	=========================================*/
	$wp_customize->add_section(
        'glides_blog_settings',
        array(
        	'priority'      => 3,
            'title' 		=> __('Sidebar','glides'),
			'panel' => 'glides_general',
		)
    );
	
	if ( class_exists( 'Glides_Customize_Control_Radio_Image' ) ) {
		// Default pages
		$wp_customize->add_setting(
			'glides_default_pg_layout', array(
				'sanitize_callback' => 'glides_sanitize_select',
				'default' => 'glides_rsb',
			)
		);

		$wp_customize->add_control(
			new Glides_Customize_Control_Radio_Image(
				$wp_customize, 'glides_default_pg_layout', array(
					'label'     => esc_html__( 'Default Page Layout', 'glides' ),
					'section'   => 'glides_blog_settings',
					'priority'  => 1,
					'choices'   => array(
						'glides_lsb' => array(
							'url' => apply_filters( 'glides_lsb', esc_url(trailingslashit( get_template_directory_uri() ) . 'inc/customizer/assets/images/lsb.svg' )),
						),
						'glides_fullwidth' => array(
							'url' => apply_filters( 'glides_fullwidth', esc_url(trailingslashit( get_template_directory_uri() ) . 'inc/customizer/assets/images/full-width.svg' )),
						),
						'glides_rsb' => array(
							'url' => apply_filters( 'glides_rsb', esc_url(trailingslashit( get_template_directory_uri() ) . 'inc/customizer/assets/images/rsb.svg' )),
						),
					),
				)
			)
		);
		// Archive pages
		$wp_customize->add_setting(
			'archive_pg_layout', array(
				'sanitize_callback' => 'glides_sanitize_select',
				'default' => 'glides_rsb',
			)
		);

		$wp_customize->add_control(
			new Glides_Customize_Control_Radio_Image(
				$wp_customize, 'archive_pg_layout', array(
					'label'     => esc_html__( 'Archive Page Layout', 'glides' ),
					'section'   => 'glides_blog_settings',
					'priority'  => 2,
					'choices'   => array(
						'glides_lsb' => array(
							'url' => apply_filters( 'glides_lsb', esc_url(trailingslashit( get_template_directory_uri() ) . 'inc/customizer/assets/images/lsb.svg' )),
						),
						'glides_fullwidth' => array(
							'url' => apply_filters( 'glides_fullwidth', esc_url(trailingslashit( get_template_directory_uri() ) . 'inc/customizer/assets/images/full-width.svg' )),
						),
						'glides_rsb' => array(
							'url' => apply_filters( 'glides_rsb', esc_url(trailingslashit( get_template_directory_uri() ) . 'inc/customizer/assets/images/rsb.svg' )),
						),
					),
				)
			)
		);
		
		// Single page
		$wp_customize->add_setting(
			'blog_single_layout', array(
				'sanitize_callback' => 'glides_sanitize_select',
				'default' => 'glides_rsb',
			)
		);

		$wp_customize->add_control(
			new Glides_Customize_Control_Radio_Image(
				$wp_customize, 'blog_single_layout', array(
					'label'     => esc_html__( 'Single Page Layout', 'glides' ),
					'section'   => 'glides_blog_settings',
					'priority'  => 3,
					'choices'   => array(
						'glides_lsb' => array(
							'url' => apply_filters( 'glides_lsb', esc_url(trailingslashit( get_template_directory_uri() ) . 'inc/customizer/assets/images/lsb.svg' )),
						),
						'glides_fullwidth' => array(
							'url' => apply_filters( 'glides_fullwidth', esc_url(trailingslashit( get_template_directory_uri() ) . 'inc/customizer/assets/images/full-width.svg' )),
						),
						'glides_rsb' => array(
							'url' => apply_filters( 'glides_rsb', esc_url(trailingslashit( get_template_directory_uri() ) . 'inc/customizer/assets/images/rsb.svg' )),
						),
					),
				)
			)
		);
		
		// Blog page
		$wp_customize->add_setting(
			'blog_page_layout', array(
				'sanitize_callback' => 'glides_sanitize_select',
				'default' => 'glides_rsb',
			)
		);

		$wp_customize->add_control(
			new Glides_Customize_Control_Radio_Image(
				$wp_customize, 'blog_page_layout', array(
					'label'     => esc_html__( 'Blog Page Layout', 'glides' ),
					'section'   => 'glides_blog_settings',
					'priority'  => 4,
					'choices'   => array(
						'glides_lsb' => array(
							'url' => apply_filters( 'glides_lsb', esc_url(trailingslashit( get_template_directory_uri() ) . 'inc/customizer/assets/images/lsb.svg' )),
						),
						'glides_fullwidth' => array(
							'url' => apply_filters( 'glides_fullwidth', esc_url(trailingslashit( get_template_directory_uri() ) . 'inc/customizer/assets/images/full-width.svg' )),
						),
						'glides_rsb' => array(
							'url' => apply_filters( 'glides_rsb', esc_url(trailingslashit( get_template_directory_uri() ) . 'inc/customizer/assets/images/rsb.svg' )),
						),
					),
				)
			)
		);
		
		// Search page
		$wp_customize->add_setting(
			'search_pg_layout', array(
				'sanitize_callback' => 'glides_sanitize_select',
				'default' => 'glides_rsb',
			)
		);

		$wp_customize->add_control(
			new Glides_Customize_Control_Radio_Image(
				$wp_customize, 'search_pg_layout', array(
					'label'     => esc_html__( 'Search Page Layout', 'glides' ),
					'section'   => 'glides_blog_settings',
					'priority'  => 5,
					'choices'   => array(
						'glides_lsb' => array(
							'url' => apply_filters( 'glides_lsb', esc_url(trailingslashit( get_template_directory_uri() ) . 'inc/customizer/assets/images/lsb.svg' )),
						),
						'glides_fullwidth' => array(
							'url' => apply_filters( 'glides_fullwidth', esc_url(trailingslashit( get_template_directory_uri() ) . 'inc/customizer/assets/images/full-width.svg' )),
						),
						'glides_rsb' => array(
							'url' => apply_filters( 'glides_rsb', esc_url(trailingslashit( get_template_directory_uri() ) . 'inc/customizer/assets/images/rsb.svg' )),
						),
					),
				)
			)
		);
	}
}
add_action( 'customize_register', 'glides_sidebar_settings' );