<?php
function expert_dental_specialist_blog_setting( $wp_customize ) {

$wp_customize->register_control_type( 'Expert_Dental_Specialist_Control_Upgrade' );

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

	// Slider Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_dental_specialist_slider_arrows' , 
			array(
			'default' => false,
			'sanitize_callback' => 'expert_dental_specialist_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	$wp_customize->add_control(
	'expert_dental_specialist_slider_arrows', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-dental-specialist' ),
			'section'     => 'expert_dental_specialist_slider_section',
			'settings'    => 'expert_dental_specialist_slider_arrows',
			'type'        => 'checkbox'
		) 
	);
	
	for ( $expert_dental_specialist_count = 1; $expert_dental_specialist_count <= 4; $expert_dental_specialist_count++ ) {

		$wp_customize->add_setting( 'expert_dental_specialist_slider_page' . $expert_dental_specialist_count, array(
			'default'           => '',
			'sanitize_callback' => 'expert_dental_specialist_sanitize_dropdown_pages'
		) );

		$wp_customize->add_control( 'expert_dental_specialist_slider_page' . $expert_dental_specialist_count, array(
			'label'    => __( 'Select Slide Image Page', 'expert-dental-specialist' ),
			'section'  => 'expert_dental_specialist_slider_section',
			'type'     => 'dropdown-pages'
		) );
	}
	
	$categories = get_categories();
	$expert_dental_specialist_offer_cat = array('select' => 'Select');

	foreach ($categories as $category) {
	    $expert_dental_specialist_offer_cat[$category->slug] = $category->name;
	}

	$wp_customize->add_setting('expert_dental_specialist_about_catData', array(
	    'default' => 'uncategorized',
	    'sanitize_callback' => 'expert_dental_specialist_sanitize_choices',
	));
	$wp_customize->add_control('expert_dental_specialist_about_catData', array(
	    'type' => 'select',
	    'choices' => $expert_dental_specialist_offer_cat,
	    'label' => __('Select a category to highlight Patient photos', 'expert-dental-specialist'),
	    'section' => 'expert_dental_specialist_slider_section',
	));

	$wp_customize->add_setting('expert_dental_specialist_customer_review', array(
	    'default' => '10k+',
	    'sanitize_callback' => 'sanitize_text_field',
	));
	$wp_customize->add_control('expert_dental_specialist_customer_review', array(
	    'label' => __('Add Total number of Patient Recover', 'expert-dental-specialist'),
	    'section' => 'expert_dental_specialist_slider_section',
	    'type' => 'text',
	));

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


	// product Section Settings
	$wp_customize->add_section('expert_dental_specialist_our_products_section', array(
	  'title' => __('Our Product Section', 'expert-dental-specialist'),
	  'panel' => 'expert_dental_specialist_frontpage_sections',
	  'priority' => 14,
	));

	// Slider Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_dental_specialist_our_products_show_hide_section' , 
			array(
			'default' => false,
			'sanitize_callback' => 'expert_dental_specialist_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	$wp_customize->add_control(
	'expert_dental_specialist_our_products_show_hide_section', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-dental-specialist' ),
			'section'     => 'expert_dental_specialist_our_products_section',
			'settings'    => 'expert_dental_specialist_our_products_show_hide_section',
			'type'        => 'checkbox'
		) 
	);

	// About Heading
	$wp_customize->add_setting( 
    	'expert_dental_specialist_our_products_small_heading_section',
    	array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);	
	$wp_customize->add_control( 
		'expert_dental_specialist_our_products_small_heading_section',
		array(
		    'label'   		=> __('Add Small Heading','expert-dental-specialist'),
		    'section'		=> 'expert_dental_specialist_our_products_section',
			'type' 			=> 'text',
		)
	);

	// About Heading
	$wp_customize->add_setting( 
    	'expert_dental_specialist_our_products_heading_section',
    	array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);	
	$wp_customize->add_control( 
		'expert_dental_specialist_our_products_heading_section',
		array(
		    'label'   		=> __('Add Heading','expert-dental-specialist'),
		    'section'		=> 'expert_dental_specialist_our_products_section',
			'type' 			=> 'text',
		)
	);

	$expert_dental_specialist_args = array(
	    'type'           => 'product',
	    'child_of'       => 0,
	    'parent'         => '',
	    'orderby'        => 'term_group',
	    'order'          => 'ASC',
	    'hide_empty'     => false,
	    'hierarchical'   => 1,
	    'number'         => '',
	    'taxonomy'       => 'product_cat',
	    'pad_counts'     => false
	);
	$categories = get_categories($expert_dental_specialist_args);
	$expert_dental_specialist_cats = array();
	$i = 0;
	foreach ($categories as $category) {
	    if ($i == 0) {
	        $default = $category->slug;
	        $i++;
	    }
	    $expert_dental_specialist_cats[$category->slug] = $category->name;
	}

	// Set the default value to "none"
	$expert_dental_specialist_default_value = 'product_cat1';

	$wp_customize->add_setting(
	    'expert_dental_specialist_our_product_product_category',
	    array(
	        'default'           => $expert_dental_specialist_default_value,
	        'sanitize_callback' => 'expert_dental_specialist_sanitize_select',
	    )
	);

	// Add "None" as an option in the select dropdown
	$expert_dental_specialist_cats_with_none = array_merge(array('none' => 'None'), $expert_dental_specialist_cats);

	$wp_customize->add_control(
	    'expert_dental_specialist_our_product_product_category',
	    array(
	        'type'    => 'select',
	        'choices' => $expert_dental_specialist_cats_with_none,
	        'label'   => __('Select Product Category', 'expert-dental-specialist'),
	        'section' => 'expert_dental_specialist_our_products_section',
	    )
	);

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

add_action( 'customize_register', 'expert_dental_specialist_blog_setting' );

// service selective refresh
function expert_dental_specialist_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_dental_specialist_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_dental_specialist_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_dental_specialist_blog_description_render_callback',
	
	) );	
	}

add_action( 'customize_register', 'expert_dental_specialist_blog_section_partials' );

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

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

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