<?php
function expert_business_consultant_blog_setting( $wp_customize ) {

$wp_customize->register_control_type( 'Expert_Business_Consultant_Control_Upgrade' );

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

	// Slider Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_business_consultant_slider_setting' , 
			array(
			'default' => true,
			'sanitize_callback' => 'expert_business_consultant_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_business_consultant_slider_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-business-consultant' ),
			'section'     => 'expert_business_consultant_slider_section',
			'settings'    => 'expert_business_consultant_slider_setting',
			'type'        => 'checkbox'
		) 
	);
	
	// Slider 1
	$wp_customize->add_setting( 
    	'expert_business_consultant_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_business_consultant_slider1',
		array(
		    'label'   		=> __('Slider 1','expert-business-consultant'),
		    'section'		=> 'expert_business_consultant_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);		

	// Slider 2
	$wp_customize->add_setting(
    	'expert_business_consultant_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_business_consultant_slider2',
		array(
		    'label'   		=> __('Slider 2','expert-business-consultant'),
		    'section'		=> 'expert_business_consultant_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);

	// Slider 3
	$wp_customize->add_setting(
    	'expert_business_consultant_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_business_consultant_slider3',
		array(
		    'label'   		=> __('Slider 3','expert-business-consultant'),
		    'section'		=> 'expert_business_consultant_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);

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

	$wp_customize->add_control( 
		'expert_business_consultant_slider_text',
		array(
		    'label'   		=> __('Slider Text','expert-business-consultant'),
		    'section'		=> 'expert_business_consultant_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);

	$wp_customize->add_setting( 'expert_business_consultant_upgrade_page_settings_2',
		array(
			'sanitize_callback' => 'sanitize_text_field'
		)
	);
	$wp_customize->add_control( new Expert_Business_Consultant_Control_Upgrade(
		$wp_customize, 'expert_business_consultant_upgrade_page_settings_2',
			array(
				'priority'      => 200,
				'section'       => 'expert_business_consultant_slider_section',
				'settings'      => 'expert_business_consultant_upgrade_page_settings_2',
				'label'         => __( 'Business Consultant Pro comes with additional features.', 'expert-business-consultant' ),
				'choices'       => array( __( '15+ Ready-Made Sections', 'expert-business-consultant' ), __( 'One-Click Demo Import', 'expert-business-consultant' ), __( 'WooCommerce Integrated', 'expert-business-consultant' ), __( 'Drag & Drop Section Reordering', 'expert-business-consultant' ),__( 'Advanced Typography Control', 'expert-business-consultant' ),__( 'Intuitive Customization Options', 'expert-business-consultant' ),__( '24/7 Support', 'expert-business-consultant' ), )
			)
		)
	);

	/*=========================================
	service Section
	=========================================*/
	$wp_customize->add_section( 
		'expert_business_consultant_courses_section' , 
		array(
	        'title'      => __( 'Popular Courses Section', 'expert-business-consultant' ),
	        'panel' => 'expert_business_consultant_frontpage_sections',
    	) 
    );

    // Adventure Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_business_consultant_courses_setting' , 
			array(
			'default' => '1',
			'sanitize_callback' => 'expert_business_consultant_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_business_consultant_courses_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-business-consultant' ),
			'section'     => 'expert_business_consultant_courses_section',
			'settings'    => 'expert_business_consultant_courses_setting',
			'type'        => 'checkbox'
		) 
	);

    $wp_customize->selective_refresh->add_partial( 
    	'expert_business_consultant_offer_section_short_title', 
    	array(
	        'selector' => '#travel-offer h2',
	        'render_callback' => 'Expert_Business_Consultant_Customize_partial_expert_business_consultant_offer_section_short_title',
    	) 
    );
    $wp_customize->add_setting(
    	'expert_business_consultant_offer_section_tittle',
    	array(
	        'default'   => '',
	        'sanitize_callback' => 'sanitize_text_field'
    	)
    );

    $wp_customize->add_control(
    	'expert_business_consultant_offer_section_tittle',
    	array(
	        'label' => __('Section Title','expert-business-consultant'),
	        'section'   => 'expert_business_consultant_courses_section',
	        'type'      => 'text'
    	)
    );

    $wp_customize->add_setting(
    	'expert_business_consultant_offer_section_text',
    	array(
	        'default'   => '',
	        'sanitize_callback' => 'sanitize_text_field'
    	)
    );
    $wp_customize->add_control(
    	'expert_business_consultant_offer_section_text',
    	array(
	        'label' => __('Section Description','expert-business-consultant'),
	        'section'   => 'expert_business_consultant_courses_section',
	        'type'      => 'text'
    	)
    );

    $expert_business_consultant_categories = get_categories();
    $expert_business_consultant_cats = array();
    $expert_business_consultant_i = 0;
    $expert_business_consultant_offer_cat[]= 'select';
    foreach($expert_business_consultant_categories as $expert_business_consultant_category){
        if($expert_business_consultant_i==0){
            $expert_business_consultant_default = $expert_business_consultant_category->slug;
            $expert_business_consultant_i++;
        }
        $expert_business_consultant_offer_cat[$expert_business_consultant_category->slug] = $expert_business_consultant_category->name;
    }

    $wp_customize->add_setting(
    	'expert_business_consultant_offer_section_category',
    	array(
	        'default'   => 'uncategorized',
	        'sanitize_callback' => 'expert_business_consultant_sanitize_choices',
    	)
    );
    $wp_customize->add_control(
    	'expert_business_consultant_offer_section_category',
    	array(
	        'type'    => 'select',
	        'choices' => $expert_business_consultant_offer_cat,
	        'label' => __('Select Category','expert-business-consultant'),
	        'section' => 'expert_business_consultant_courses_section',
    	)
    );

   // Setting for number of posts to show
    $wp_customize->add_setting('expert_business_consultant_posts_to_show', array(
        'default'           => 3, // Default number of posts to show
        'sanitize_callback' => 'absint', // Sanitization callback
    ));

    // Add control for number of posts to show
    $wp_customize->add_control('expert_business_consultant_posts_to_show', array(
        'label'       => __('Number of Popular Online Courses to Show', 'expert-business-consultant'),
        'section'     => 'expert_business_consultant_courses_section',
        'priority'    => 10,
        'type'        => 'number',
        'input_attrs' => array(
            'step' => 1,
            'min'  => 0,
            'max'  => 50,
        ),
    ));

    // Get the number of posts to show
    $expert_business_consultant_posts_to_show = get_theme_mod('expert_business_consultant_posts_to_show', 6);
    
    // Loop to create settings and controls for each post's price and star rating
    for ($expert_business_consultant_i = 1; $expert_business_consultant_i <= $expert_business_consultant_posts_to_show; $expert_business_consultant_i++) {
        $wp_customize->add_setting('expert_business_consultant_courses_prices' . $expert_business_consultant_i, array(
            'default' => '',
            'sanitize_callback' => 'sanitize_text_field'
        ));

        $wp_customize->add_control('expert_business_consultant_courses_prices' . $expert_business_consultant_i, array(
            'label'    => __('Add Courses Price ', 'expert-business-consultant') . $expert_business_consultant_i,
            'section'  => 'expert_business_consultant_courses_section',
            'type'     => 'text',
            'priority' => 998,
        ));

        $wp_customize->add_setting('expert_business_consultant_star_rating' . $expert_business_consultant_i, array(
            'default'           => '3',
            'sanitize_callback' => 'absint',
        ));

        $wp_customize->add_control('expert_business_consultant_star_rating' . $expert_business_consultant_i, array(
            'label'       => __('Add Rating for Post ', 'expert-business-consultant') . $expert_business_consultant_i,
            'section'     => 'expert_business_consultant_courses_section',
            'priority'    => 999,
            'type'        => 'number',
            'input_attrs' => array(
                'step' => 1,
                'min'  => 0,
                'max'  => 5,
            ),
        ));
    }

	$wp_customize->add_setting( 'expert_business_consultant_upgrade_page_settings_2ad',
		array(
			'sanitize_callback' => 'sanitize_text_field'
		)
	);
	$wp_customize->add_control( new Expert_Business_Consultant_Control_Upgrade(
		$wp_customize, 'expert_business_consultant_upgrade_page_settings_2ad',
			array(
				'priority'      => 200,
				'section'       => 'expert_business_consultant_courses_section',
				'settings'      => 'expert_business_consultant_upgrade_page_settings_2ad',
				'label'         => __( 'Business Consultant Pro comes with additional features.', 'expert-business-consultant' ),
				'choices'       => array( __( '15+ Ready-Made Sections', 'expert-business-consultant' ), __( 'One-Click Demo Import', 'expert-business-consultant' ), __( 'WooCommerce Integrated', 'expert-business-consultant' ), __( 'Drag & Drop Section Reordering', 'expert-business-consultant' ),__( 'Advanced Typography Control', 'expert-business-consultant' ),__( 'Intuitive Customization Options', 'expert-business-consultant' ),__( '24/7 Support', 'expert-business-consultant' ), )
			)
		)
	);
}


add_action( 'customize_register', 'expert_business_consultant_blog_setting' );

// service selective refresh
function expert_business_consultant_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_business_consultant_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_business_consultant_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_business_consultant_blog_description_render_callback',
	
	) );	
	}

add_action( 'customize_register', 'expert_business_consultant_blog_section_partials' );

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

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

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