<?php
function expert_construction_company_blog_setting( $wp_customize ) {

$wp_customize->register_control_type( 'Expert_Construction_Company_Control_Upgrade' );

$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';
	$wp_customize->add_panel(
		'expert_construction_company_frontpage_sections', array(
			'priority' => 1,
			'title' => esc_html__( 'Frontpage Sections', 'expert-construction-company' ),
		)
	);
	
	/*=========================================
	Slider Section
	=========================================*/
	$wp_customize->add_section(
		'expert_construction_company_slider_section', array(
			'title' => esc_html__( 'Slider Section', 'expert-construction-company' ),
			'priority' => 3,
			'panel' => 'expert_construction_company_frontpage_sections',
		)
	);

	// Slider Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_construction_company_slider_setting' , 
			array(
			'default' => false,
			'sanitize_callback' => 'expert_construction_company_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_construction_company_slider_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-construction-company' ),
			'section'     => 'expert_construction_company_slider_section',
			'settings'    => 'expert_construction_company_slider_setting',
			'type'        => 'checkbox'
		) 
	);
	
	for ( $expert_construction_company_count = 1; $expert_construction_company_count <= 4; $expert_construction_company_count++ ) {

	// Add color scheme setting and control.
	$wp_customize->add_setting( 'expert_construction_company_slider_page' . $expert_construction_company_count, array(
		'default'           => '',
		'sanitize_callback' => 'expert_construction_company_sanitize_dropdown_pages'
	) );

	$wp_customize->add_control( 'expert_construction_company_slider_page' . $expert_construction_company_count, array(
		'label'    => __( 'Select Slide Image Page', 'expert-construction-company' ),
		'section'  => 'expert_construction_company_slider_section',
		'type'     => 'dropdown-pages'
	) );
	}

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

	$wp_customize->add_control( 
		'expert_construction_company_slider_short_heading',
		array(
		    'label'   		=> __('Slider Top Text','expert-construction-company'),
		    'section'		=> 'expert_construction_company_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);

	$wp_customize->add_setting(
    	'expert_construction_company_slider_btn_text',
    	array(
			'default' => 'MAKE AN APPOINTMENT',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'expert_construction_company_slider_btn_text',
		array(
		    'label'   		=> __('Slider Button Text 2','expert-construction-company'),
		    'section'		=> 'expert_construction_company_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)  
	);

	$wp_customize->add_setting(
    	'expert_construction_company_slider_btn_link',
    	array(
			'default' => '',
			'sanitize_callback' => 'esc_url_raw',
		)
	);
	$wp_customize->add_control( 
		'expert_construction_company_slider_btn_link',
		array(
		    'label'   		=> __('Slider Button Link 2','expert-construction-company'),
		    'section'		=> 'expert_construction_company_slider_section',
			'type' 			=> 'url',
			'transport'         => $selective_refresh,
		)
	);

	$wp_customize->add_setting('expert_construction_company_slider_below_call_text',array(
		'default'=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('expert_construction_company_slider_below_call_text',array(
		'label'	=> __('Add Appointment Text','expert-construction-company'),
		'section'=> 'expert_construction_company_slider_section',
		'type'=> 'text'
	));

	$wp_customize->add_setting('expert_construction_company_slider_below_call',array(
		'default'=> '',
		'sanitize_callback'	=> 'expert_construction_company_sanitize_phone_number'
	));
	$wp_customize->add_control('expert_construction_company_slider_below_call',array(
		'label'	=> __('Add Phone Number','expert-construction-company'),
		'section'=> 'expert_construction_company_slider_section',
		'type'=> 'text'
	));

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

	// Service Section Settings
	$wp_customize->add_section('expert_construction_company_service_section', array(
	  'title' => __('Our Services Settings', 'expert-construction-company'),
	  'panel' => 'expert_construction_company_frontpage_sections',
	  'priority' => 14,
	));

	// About Us Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_construction_company_show_hide_sec' , 
			array(
			'default' => true,
			'sanitize_callback' => 'expert_construction_company_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	$wp_customize->add_control(
	'expert_construction_company_show_hide_sec', 
		array(
			'label'	      => esc_html__( 'Show / Hide Service Section', 'expert-construction-company' ),
			'section'     => 'expert_construction_company_service_section',
			'settings'    => 'expert_construction_company_show_hide_sec',
			'type'        => 'checkbox'
		) 
	);

	$wp_customize->add_setting('expert_construction_company_serv_short_heading',array(
		'default'=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('expert_construction_company_serv_short_heading',array(
		'label'	=> __('Add short Heading','expert-construction-company'),
		'section'=> 'expert_construction_company_service_section',
		'type'=> 'text'
	));

	$wp_customize->add_setting('expert_construction_company_featured_section_title', array(
	  'default' => '',
	  'sanitize_callback' => 'sanitize_text_field'
	));
	$wp_customize->add_control('expert_construction_company_featured_section_title', array(
	  'label' => __('Add Heading', 'expert-construction-company'),
	  'section' => 'expert_construction_company_service_section',
	  'type' => 'text'
	));

	$expert_construction_company_categories = get_categories();
	$cats = array();
	$expert_construction_company_i = 0;
	$expert_construction_company_offer_cat[] = 'select';
	foreach ($expert_construction_company_categories as $expert_construction_company_category) {
	  if ($expert_construction_company_i == 0) {
	    $expert_construction_company_default = $expert_construction_company_category->slug;
	    $expert_construction_company_i++;
	  }
	  $expert_construction_company_offer_cat[$expert_construction_company_category->slug] = $expert_construction_company_category->name;
	}

	$wp_customize->add_setting('expert_construction_company_featured_section_category', array(
	  'default' => 'uncategorized',
	  'sanitize_callback' => 'expert_construction_company_sanitize_choices',
	));
	$wp_customize->add_control('expert_construction_company_featured_section_category', array(
	  'type' => 'select',
	  'choices' => $expert_construction_company_offer_cat,
	  'label' => __('Select Category', 'expert-construction-company'),
	  'section' => 'expert_construction_company_service_section',
	));

	$wp_customize->add_setting('expert_construction_company_num_posts', array(
	  'default' => 3,
	  'sanitize_callback' => 'absint',
	));
	$wp_customize->add_control('expert_construction_company_num_posts', array(
	  'label' => __('Number of Posts to Show', 'expert-construction-company'),
	  'section' => 'expert_construction_company_service_section',
	  'type' => 'number',
	));

	$expert_construction_company_services_count = get_theme_mod('expert_construction_company_num_posts', 3);

	for ($expert_construction_company_i = 1; $expert_construction_company_i <= $expert_construction_company_services_count; $expert_construction_company_i++) {
		
	  $wp_customize->add_setting('expert_construction_company_services_icon' . $expert_construction_company_i, array(
	    'default' => 'fas fa-house-user',
	    'sanitize_callback' => 'sanitize_text_field'
	  ));
	  $wp_customize->add_control('expert_construction_company_services_icon' . $expert_construction_company_i, array(
	    'label' => __('Icon ', 'expert-construction-company') . $expert_construction_company_i,
	    'description' => __('Use Font Awesome icons like fas fa-phone', 'expert-construction-company'),
	    'section' => 'expert_construction_company_service_section',
	    'type' => 'text'
	  ));
	}

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

add_action( 'customize_register', 'expert_construction_company_blog_setting' );

// service selective refresh
function expert_construction_company_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_construction_company_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_construction_company_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_construction_company_blog_description_render_callback',
	
	) );	
	}

add_action( 'customize_register', 'expert_construction_company_blog_section_partials' );

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

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

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