<?php
function expert_ac_repair_blog_setting( $wp_customize ) {

$wp_customize->register_control_type( 'Expert_Ac_Repair_Control_Upgrade' );

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

	// Slider Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_ac_repair_slider_setting' , 
			array(
			'default' => true,
			'sanitize_callback' => 'expert_ac_repair_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_ac_repair_slider_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-ac-repair' ),
			'section'     => 'expert_ac_repair_slider_section',
			'settings'    => 'expert_ac_repair_slider_setting',
			'type'        => 'checkbox'
		) 
	);
	
	for ( $expert_ac_repair_count = 1; $expert_ac_repair_count <= 3; $expert_ac_repair_count++ ) {

	// Add color scheme setting and control.
	$wp_customize->add_setting( 'expert_ac_repair_slider_page' . $expert_ac_repair_count, array(
		'default'           => '',
		'sanitize_callback' => 'expert_ac_repair_sanitize_dropdown_pages'
	) );
	$wp_customize->add_control( 'expert_ac_repair_slider_page' . $expert_ac_repair_count, array(
		'label'    => __( 'Select Slide Image Page', 'expert-ac-repair' ),
		'section'  => 'expert_ac_repair_slider_section',
		'type'     => 'dropdown-pages'
	) );
	}

	// Slider Text
	$wp_customize->add_setting( 
    	'expert_ac_repair_slider_short_heading',
    	array(
			'capability'     	=> 'edit_theme_options',
			'default'           => '24-Hours Emergency Service',
			'sanitize_callback' => 'sanitize_text_field',
			'priority'      => 1,
		)
	);	

	$wp_customize->add_control( 
		'expert_ac_repair_slider_short_heading',
		array(
		    'label'   		=> __('Slider Top Text','expert-ac-repair'),
		    'section'		=> 'expert_ac_repair_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);

	$wp_customize->add_setting(
    	'expert_ac_repair_slider_btn_text',
    	array(
			'default' => 'LEARN MORE',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'expert_ac_repair_slider_btn_text',
		array(
		    'label'   		=> __('Slider Button Text','expert-ac-repair'),
		    'section'		=> 'expert_ac_repair_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)  
	);

	$wp_customize->add_setting(
    	'expert_ac_repair_slider_btn_link',
    	array(
			'default' => '',
			'sanitize_callback' => 'esc_url_raw',
		)
	);
	$wp_customize->add_control( 
		'expert_ac_repair_slider_btn_link',
		array(
		    'label'   		=> __('Slider Button Link','expert-ac-repair'),
		    'section'		=> 'expert_ac_repair_slider_section',
			'type' 			=> 'url',
			'transport'         => $selective_refresh,
		)
	);

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


	// Service Section Settings
	$wp_customize->add_section('expert_ac_repair_service_section', array(
	  'title' => __('Our Services Section', 'expert-ac-repair'),
	  'panel' => 'expert_ac_repair_frontpage_sections',
	  'priority' => 14,
	));

	// About Us Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_ac_repair_show_hide_sec' , 
			array(
			'default' => false,
			'sanitize_callback' => 'expert_ac_repair_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	$wp_customize->add_control(
	'expert_ac_repair_show_hide_sec', 
		array(
			'label'	      => esc_html__( 'Show / Hide Service Section', 'expert-ac-repair' ),
			'section'     => 'expert_ac_repair_service_section',
			'settings'    => 'expert_ac_repair_show_hide_sec',
			'type'        => 'checkbox'
		) 
	);

	$wp_customize->add_setting('expert_ac_repair_serv_short_heading',array(
		'default'=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('expert_ac_repair_serv_short_heading',array(
		'label'	=> __('Add short Heading','expert-ac-repair'),
		'section'=> 'expert_ac_repair_service_section',
		'type'=> 'text'
	));

	$wp_customize->add_setting('expert_ac_repair_featured_section_title', array(
	  'default' => '',
	  'sanitize_callback' => 'sanitize_text_field'
	));
	$wp_customize->add_control('expert_ac_repair_featured_section_title', array(
	  'label' => __('Add Heading', 'expert-ac-repair'),
	  'section' => 'expert_ac_repair_service_section',
	  'type' => 'text'
	));

	$expert_ac_repair_categories = get_categories();
	$cats = array();
	$expert_ac_repair_i = 0;
	$expert_ac_repair_offer_cat[] = 'select';
	foreach ($expert_ac_repair_categories as $expert_ac_repair_category) {
	  if ($expert_ac_repair_i == 0) {
	    $expert_ac_repair_default = $expert_ac_repair_category->slug;
	    $expert_ac_repair_i++;
	  }
	  $expert_ac_repair_offer_cat[$expert_ac_repair_category->slug] = $expert_ac_repair_category->name;
	}

	$wp_customize->add_setting('expert_ac_repair_featured_section_category', array(
	  'default' => 'uncategorized',
	  'sanitize_callback' => 'expert_ac_repair_sanitize_choices',
	));
	$wp_customize->add_control('expert_ac_repair_featured_section_category', array(
	  'type' => 'select',
	  'choices' => $expert_ac_repair_offer_cat,
	  'label' => __('Select Category', 'expert-ac-repair'),
	  'section' => 'expert_ac_repair_service_section',
	));

	$wp_customize->add_setting('expert_ac_repair_num_posts', array(
	  'default' => 3,
	  'sanitize_callback' => 'absint',
	));
	$wp_customize->add_control('expert_ac_repair_num_posts', array(
	  'label' => __('Number of Posts to Show', 'expert-ac-repair'),
	  'section' => 'expert_ac_repair_service_section',
	  'type' => 'number',
	));

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

add_action( 'customize_register', 'expert_ac_repair_blog_setting' );

// service selective refresh
function expert_ac_repair_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_ac_repair_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_ac_repair_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_ac_repair_blog_description_render_callback',
	
	) );	
	}

add_action( 'customize_register', 'expert_ac_repair_blog_section_partials' );

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

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

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