<?php
function expert_digital_agency_blog_setting( $wp_customize ) {

$wp_customize->register_control_type( 'Expert_Digital_Agency_Control_Upgrade' );

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

	// Slider Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_digital_agency_slider_setting' , 
			array(
			'default' => true,
			'sanitize_callback' => 'expert_digital_agency_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_digital_agency_slider_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-digital-agency' ),
			'section'     => 'expert_digital_agency_slider_section',
			'settings'    => 'expert_digital_agency_slider_setting',
			'type'        => 'checkbox'
		) 
	);
	
	// Slider 1
	$wp_customize->add_setting( 
    	'expert_digital_agency_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_digital_agency_slider1',
		array(
		    'label'   		=> __('Slider 1','expert-digital-agency'),
		    'section'		=> 'expert_digital_agency_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);		

	// Slider 2
	$wp_customize->add_setting(
    	'expert_digital_agency_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_digital_agency_slider2',
		array(
		    'label'   		=> __('Slider 2','expert-digital-agency'),
		    'section'		=> 'expert_digital_agency_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);

	// Slider 3
	$wp_customize->add_setting(
    	'expert_digital_agency_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_digital_agency_slider3',
		array(
		    'label'   		=> __('Slider 3','expert-digital-agency'),
		    'section'		=> 'expert_digital_agency_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);

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

	$wp_customize->add_control( 
		'expert_digital_agency_slider_text',
		array(
		    'label'   		=> __('Slider Text','expert-digital-agency'),
		    'section'		=> 'expert_digital_agency_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);

	$wp_customize->add_setting(
    	'expert_digital_agency_slider_btn_text',
    	array(
			'default' => '',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'expert_digital_agency_slider_btn_text',
		array(
		    'label'   		=> __('Slider Button Text','expert-digital-agency'),
		    'section'		=> 'expert_digital_agency_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)  
	);

	$wp_customize->add_setting(
    	'expert_digital_agency_slider_btn_link',
    	array(
			'default' => '',
			'sanitize_callback' => 'esc_url_raw',
		)
	);
	$wp_customize->add_control( 
		'expert_digital_agency_slider_btn_link',
		array(
		    'label'   		=> __('Slider Button Link','expert-digital-agency'),
		    'section'		=> 'expert_digital_agency_slider_section',
			'type' 			=> 'url',
			'transport'         => $selective_refresh,
		)
	);

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

	/*=========================================
	service Section
	=========================================*/

	$wp_customize->add_section(
		'expert_digital_agency_service_section', array(
			'title' => esc_html__( 'Our Services Section', 'expert-digital-agency' ),
			'priority' => 14,
			'panel' => 'expert_digital_agency_frontpage_sections',
		)
	);

	// Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_digital_agency_service_show_hide' , 
			array(
			'default' => true,
			'sanitize_callback' => 'expert_digital_agency_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_digital_agency_service_show_hide', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-digital-agency' ),
			'section'     => 'expert_digital_agency_service_section',
			'settings'    => 'expert_digital_agency_service_show_hide',
			'type'        => 'checkbox'
		) 
	);

	// Button Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_digital_agency_serv_button_setting' , 
			array(
			'default' => '1',
			'sanitize_callback' => 'expert_digital_agency_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_digital_agency_serv_button_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Button', 'expert-digital-agency' ),
			'section'     => 'expert_digital_agency_service_section',
			'settings'    => 'expert_digital_agency_serv_button_setting',
			'type'        => 'checkbox'
		) 
	);

	$wp_customize->add_setting(
    	'expert_digital_agency_section_title',
    	array(
			'default' => '',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);	
	$wp_customize->add_control( 
		'expert_digital_agency_section_title',
		array(
		    'label'   		=> __('Title','expert-digital-agency'),
		    'section'		=> 'expert_digital_agency_service_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);

	$wp_customize->add_setting(
    	'expert_digital_agency_section_text',
    	array(
			'default' => '',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);	
	$wp_customize->add_control( 
		'expert_digital_agency_section_text',
		array(
		    'label'   		=> __('Section Text','expert-digital-agency'),
		    'section'		=> 'expert_digital_agency_service_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);


	$expert_digital_agency_categories = get_categories();
    $expert_digital_agency_cats = array();
    $expert_digital_agency_i = 0;
    $expert_digital_agency_offer_cat[]= 'select';
    foreach($expert_digital_agency_categories as $expert_digital_agency_category){
        if($expert_digital_agency_i==0){
            $expert_digital_agency_default = $expert_digital_agency_category->slug;
            $expert_digital_agency_i++;
        }
        $expert_digital_agency_offer_cat[$expert_digital_agency_category->slug] = $expert_digital_agency_category->name;
    }

    $wp_customize->add_setting(
    	'expert_digital_agency_offer_section_category',
    	array(
	        'default'   => 'uncategorized',
	        'sanitize_callback' => 'expert_digital_agency_sanitize_choices',
    	)
    );
    $wp_customize->add_control(
    	'expert_digital_agency_offer_section_category',
    	array(
	        'type'    => 'select',
	        'choices' => $expert_digital_agency_offer_cat,
	        'label' => __('Select Category','expert-digital-agency'),
	        'section' => 'expert_digital_agency_service_section',
    	)
    );

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

add_action( 'customize_register', 'expert_digital_agency_blog_setting' );

// service selective refresh
function expert_digital_agency_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_digital_agency_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_digital_agency_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_digital_agency_blog_description_render_callback',
	
	) );	
	}

add_action( 'customize_register', 'expert_digital_agency_blog_section_partials' );

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

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

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