<?php
function expert_ngo_volunteer_blog_setting( $wp_customize ) {

$wp_customize->register_control_type( 'Expert_NGO_Volunteer_Control_Upgrade' );

$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';
	$wp_customize->add_panel(
		'expert_ngo_volunteer_frontpage_sections', array(
			'priority' => 1,
			'title' => esc_html__( 'Frontpage Sections', 'expert-ngo-volunteer' ),
		)
	);
	
	/*=========================================
	Slider Section
	=========================================*/
	$wp_customize->add_section(
		'expert_ngo_volunteer_slider_section', array(
			'title' => esc_html__( 'Slider Section', 'expert-ngo-volunteer' ),
			'priority' => 13,
			'panel' => 'expert_ngo_volunteer_frontpage_sections',
		)
	);

	// Slider Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_ngo_volunteer_slider_setting' , 
			array(
			'default' => true,
			'sanitize_callback' => 'expert_ngo_volunteer_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_ngo_volunteer_slider_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-ngo-volunteer' ),
			'section'     => 'expert_ngo_volunteer_slider_section',
			'settings'    => 'expert_ngo_volunteer_slider_setting',
			'type'        => 'checkbox'
		) 
	);
	
	// Slider 1
	$wp_customize->add_setting( 
    	'expert_ngo_volunteer_slider1',
    	array(
            'default'           => get_page_id_by_slug('slider-page'),
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'wp_kses_post',
			'priority'      => 1,
		)
	);	

	$wp_customize->add_control( 
		'expert_ngo_volunteer_slider1',
		array(
		    'label'   		=> __('Slider 1','expert-ngo-volunteer'),
		    'section'		=> 'expert_ngo_volunteer_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);		

	// Slider 2
	$wp_customize->add_setting(
    	'expert_ngo_volunteer_slider2',
    	array(
            'default'           => get_page_id_by_slug('slider-pages'),
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'wp_kses_post',
			'priority'      => 2,
		)
	);

	$wp_customize->add_control( 
		'expert_ngo_volunteer_slider2',
		array(
		    'label'   		=> __('Slider 2','expert-ngo-volunteer'),
		    'section'		=> 'expert_ngo_volunteer_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);

	// Slider 3
	$wp_customize->add_setting(
    	'expert_ngo_volunteer_slider3',
    	array(
            'default'           => get_page_id_by_slug('slider-pagess'),
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'wp_kses_post',
			'priority'      => 3,
		)
	);

	$wp_customize->add_control( 
		'expert_ngo_volunteer_slider3',
		array(
		    'label'   		=> __('Slider 3','expert-ngo-volunteer'),
		    'section'		=> 'expert_ngo_volunteer_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);

	// Slider Text
	$wp_customize->add_setting( 
    	'expert_ngo_volunteer_slider_text',
    	array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'sanitize_text_field',
			'priority'      => 1,
		)
	);	

	$wp_customize->add_control( 
		'expert_ngo_volunteer_slider_text',
		array(
		    'label'   		=> __('Add Slider Top Text','expert-ngo-volunteer'),
		    'section'		=> 'expert_ngo_volunteer_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);

	$wp_customize->add_setting('expert_ngo_volunteer_total_no_charity_experience',array(
		'default'	=> '10+ years',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('expert_ngo_volunteer_total_no_charity_experience',array(
		'label'	=> __('Add Total Number of Years','expert-ngo-volunteer'),
		'section'	=> 'expert_ngo_volunteer_slider_section',
		'type'		=> 'text'
	));

	$wp_customize->add_setting( 'expert_ngo_volunteer_upgrade_page_settings_3',
        array(
            'sanitize_callback' => 'sanitize_text_field'
        )
    );
    $wp_customize->add_control( new Expert_NGO_Volunteer_Control_Upgrade(
        $wp_customize, 'expert_ngo_volunteer_upgrade_page_settings_3',
            array(
                'priority'      => 200,
                'section'       => 'expert_ngo_volunteer_slider_section',
                'settings'      => 'expert_ngo_volunteer_upgrade_page_settings_3',
                'label'         => __( 'Expert NGO Volunteer Pro comes with additional features.', 'expert-ngo-volunteer' ),
                'choices'       => array( __( '15+ Ready-Made Sections', 'expert-ngo-volunteer' ), __( 'One-Click Demo Import', 'expert-ngo-volunteer' ), __( 'WooCommerce Integrated', 'expert-ngo-volunteer' ), __( 'Drag & Drop Section Reordering', 'expert-ngo-volunteer' ),__( 'Advanced Typography Control', 'expert-ngo-volunteer' ),__( 'Intuitive Customization Options', 'expert-ngo-volunteer' ),__( '24/7 Support', 'expert-ngo-volunteer' ), )
            )
        )
    ); 

	// About Us Section
	$wp_customize->add_section('expert_ngo_volunteer_service_section', array(
	    'title'    => __('About Us Section', 'expert-ngo-volunteer'),
	    'panel'    => 'expert_ngo_volunteer_frontpage_sections',
	    'priority' => 14,
	));

	// Slider Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_ngo_volunteer_service_enable' , 
			array(
			'default' => true,
			'sanitize_callback' => 'expert_ngo_volunteer_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_ngo_volunteer_service_enable', 
		array(
			'label'	      => esc_html__( 'Show / Hide About', 'expert-ngo-volunteer' ),
			'section'     => 'expert_ngo_volunteer_service_section',
			'settings'    => 'expert_ngo_volunteer_service_enable',
			'type'        => 'checkbox'
		) 
	);

	// Add a default "Select" option to the dropdown
	$wp_customize->add_setting('expert_ngo_volunteer_about_page', array(
		'default'           => get_page_id_by_slug('donate-page'),
	    'sanitize_callback' => 'expert_ngo_volunteer_sanitize_dropdown_pages'
	));
	$wp_customize->add_control('expert_ngo_volunteer_about_page', array(
	    'label'    => __('Select Services Page', 'expert-ngo-volunteer'),
	    'section'  => 'expert_ngo_volunteer_service_section',
	    'type'     => 'dropdown-pages'
	));
	
	$wp_customize->add_setting('expert_ngo_volunteer_service_sub_heading', array(
	    'default'           => '',
	    'sanitize_callback' => 'sanitize_text_field'
	));
	$wp_customize->add_control('expert_ngo_volunteer_service_sub_heading', array(
	    'label'    => __('Section Sub Title', 'expert-ngo-volunteer'),
	    'section'  => 'expert_ngo_volunteer_service_section',
	    'type'     => 'text'
	));

	// YouTube URL
	$wp_customize->add_setting(
	    'expert_ngo_volunteer_youtube_url',
	    array(
	        'default'           => '#',
	        'sanitize_callback' => 'esc_url_raw',
	    )
	);
	$wp_customize->add_control(
	    'expert_ngo_volunteer_youtube_url',
	    array(
	        'type'    => 'url',
	        'label'   => __('YouTube URL', 'expert-ngo-volunteer'),
	        'section' => 'expert_ngo_volunteer_service_section',
	    )
	);

	$wp_customize->add_setting( 'expert_ngo_volunteer_upgrade_page_settings_4',
        array(
            'sanitize_callback' => 'sanitize_text_field'
        )
    );
    $wp_customize->add_control( new Expert_NGO_Volunteer_Control_Upgrade(
        $wp_customize, 'expert_ngo_volunteer_upgrade_page_settings_4',
            array(
                'priority'      => 200,
                'section'       => 'expert_ngo_volunteer_service_section',
                'settings'      => 'expert_ngo_volunteer_upgrade_page_settings_4',
                'label'         => __( 'Expert NGO Volunteer Pro comes with additional features.', 'expert-ngo-volunteer' ),
                'choices'       => array( __( '15+ Ready-Made Sections', 'expert-ngo-volunteer' ), __( 'One-Click Demo Import', 'expert-ngo-volunteer' ), __( 'WooCommerce Integrated', 'expert-ngo-volunteer' ), __( 'Drag & Drop Section Reordering', 'expert-ngo-volunteer' ),__( 'Advanced Typography Control', 'expert-ngo-volunteer' ),__( 'Intuitive Customization Options', 'expert-ngo-volunteer' ),__( '24/7 Support', 'expert-ngo-volunteer' ), )
            )
        )
    ); 
}

add_action( 'customize_register', 'expert_ngo_volunteer_blog_setting' );

// service selective refresh
function expert_ngo_volunteer_blog_section_partials( $wp_customize ){	
	// blog_title
	$wp_customize->selective_refresh->add_partial( 'blog_title', array(
		'selector'            => '.home-blog .title h6',
		'settings'            => 'blog_title',
		'render_callback'  => 'expert_ngo_volunteer_blog_title_render_callback',
	
	) );
	
	// blog_subtitle
	$wp_customize->selective_refresh->add_partial( 'blog_subtitle', array(
		'selector'            => '.home-blog .title h2',
		'settings'            => 'blog_subtitle',
		'render_callback'  => 'expert_ngo_volunteer_blog_subtitle_render_callback',
	
	) );
	
	// blog_description
	$wp_customize->selective_refresh->add_partial( 'blog_description', array(
		'selector'            => '.home-blog .title p',
		'settings'            => 'blog_description',
		'render_callback'  => 'expert_ngo_volunteer_blog_description_render_callback',
	
	) );	
	}

add_action( 'customize_register', 'expert_ngo_volunteer_blog_section_partials' );

// blog_title
function expert_ngo_volunteer_blog_title_render_callback() {
	return get_theme_mod( 'blog_title' );
}

// blog_subtitle
function expert_ngo_volunteer_blog_subtitle_render_callback() {
	return get_theme_mod( 'blog_subtitle' );
}

// service description
function expert_ngo_volunteer_blog_description_render_callback() {
	return get_theme_mod( 'blog_description' );
}