<?php
function expert_videographer_blog_setting( $wp_customize ) {
$wp_customize->register_control_type( 'Expert_Videographer_Control_Upgrade' );
$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';
	$wp_customize->add_panel(
		'expert_videographer_frontpage_sections', array(
			'priority' => 1,
			'title' => esc_html__( 'Frontpage Sections', 'expert-videographer' ),
		)
	);
	
	/*=========================================
	Slider Section
	=========================================*/
	$wp_customize->add_section(
		'expert_videographer_slider_section', array(
			'title' => esc_html__( 'Slider Section', 'expert-videographer' ),
			'priority' => 13,
			'panel' => 'expert_videographer_frontpage_sections',
		)
	);

	// Slider Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_videographer_slider_setting' , 
			array(
			'default' => true,
			'sanitize_callback' => 'expert_videographer_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_videographer_slider_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-videographer' ),
			'section'     => 'expert_videographer_slider_section',
			'settings'    => 'expert_videographer_slider_setting',
			'type'        => 'checkbox'
		) 
	);
	
	// Slider 1
	$wp_customize->add_setting( 
    	'expert_videographer_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_videographer_slider1',
		array(
		    'label'   		=> __('Slider 1','expert-videographer'),
		    'section'		=> 'expert_videographer_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);		

	// Slider 2
	$wp_customize->add_setting(
    	'expert_videographer_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_videographer_slider2',
		array(
		    'label'   		=> __('Slider 2','expert-videographer'),
		    'section'		=> 'expert_videographer_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);

	// Slider 3
	$wp_customize->add_setting(
    	'expert_videographer_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_videographer_slider3',
		array(
		    'label'   		=> __('Slider 3','expert-videographer'),
		    'section'		=> 'expert_videographer_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);

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

	$wp_customize->add_control( 
		'expert_videographer_slider_text',
		array(
		    'label'   		=> __('Add Slider Top Text','expert-videographer'),
		    'section'		=> 'expert_videographer_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);

	$wp_customize->add_setting(
    	'expert_videographer_slider_btn_text',
    	array(
			'default' => 'Info More',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'expert_videographer_slider_btn_text',
		array(
		    'label'   		=> __('Slider Button Text 2','expert-videographer'),
		    'section'		=> 'expert_videographer_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)  
	);

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

	$wp_customize->add_setting('expert_videographer_customer_img',array(
		'sanitize_callback'	=> 'esc_url_raw',
	));
	$wp_customize->add_control( new WP_Customize_Image_Control($wp_customize,'expert_videographer_customer_img',array(
	    'label' => __('Add Award Photo','expert-videographer'),
	     'section' => 'expert_videographer_slider_section'
	)));

	// name
	$wp_customize->add_setting(
	    'expert_videographer_award_name',
	    array(
	        'sanitize_callback' => 'sanitize_text_field',
	    )
	);
	$wp_customize->add_control(
	    'expert_videographer_award_name',
	    array(
	        'type'    => 'text',
	        'label'   => __('Add Best Year of Annual Award', 'expert-videographer'),
	        'section' => 'expert_videographer_slider_section',
	    )
	);

	$wp_customize->add_setting('expert_videographer_facebook_url',array(
		'default'=> '',
		'sanitize_callback'	=> 'esc_url_raw'
	));
	$wp_customize->add_control('expert_videographer_facebook_url',array(
		'label'	=> __('Facebook Link','expert-videographer'),
		'section'=> 'expert_videographer_slider_section',
		'type'=> 'url'
	));

	$wp_customize->add_setting('expert_videographer_twitter_url',array(
		'default'=> '',
		'sanitize_callback'	=> 'esc_url_raw'
	));
	$wp_customize->add_control('expert_videographer_twitter_url',array(
		'label'	=> __('Twitter Link','expert-videographer'),
		'section'=> 'expert_videographer_slider_section',
		'type'=> 'url'
	));

	$wp_customize->add_setting('expert_videographer_instagram_url',array(
		'default'=> '',
		'sanitize_callback'	=> 'esc_url_raw'
	));
	$wp_customize->add_control('expert_videographer_instagram_url',array(
		'label'	=> __('Instagram Link','expert-videographer'),
		'section'=> 'expert_videographer_slider_section',
		'type'=> 'url'
	));

	$wp_customize->add_setting('expert_videographer_youtube_url',array(
		'default'=> '',
		'sanitize_callback'	=> 'esc_url_raw'
	));
	$wp_customize->add_control('expert_videographer_youtube_url',array(
		'label'	=> __('Youtube Link','expert-videographer'),
		'section'=> 'expert_videographer_slider_section',
		'type'=> 'url'
	));

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

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

	$wp_customize->add_section(
		'expert_videographer_service_section', array(
			'title' => esc_html__( 'Our Services Section', 'expert-videographer' ),
			'priority' => 14,
			'panel' => 'expert_videographer_frontpage_sections',
		)
	);

	// Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_videographer_service_show_hide' , 
			array(
			'default' => true,
			'sanitize_callback' => 'expert_videographer_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_videographer_service_show_hide', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-videographer' ),
			'section'     => 'expert_videographer_service_section',
			'settings'    => 'expert_videographer_service_show_hide',
			'type'        => 'checkbox'
		) 
	);

	$wp_customize->add_setting(
    	'expert_videographer_section_small_text',
    	array(
			'default' => '',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);	
	$wp_customize->add_control( 
		'expert_videographer_section_small_text',
		array(
		    'label'   		=> __('Add Small Title','expert-videographer'),
		    'section'		=> 'expert_videographer_service_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);

	$wp_customize->add_setting(
    	'expert_videographer_section_title',
    	array(
			'default' => '',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);	
	$wp_customize->add_control( 
		'expert_videographer_section_title',
		array(
		    'label'   		=> __('Add Heading','expert-videographer'),
		    'section'		=> 'expert_videographer_service_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);

	$expert_videographer_categories = get_categories();
    $expert_videographer_cats = array();
    $expert_videographer_i = 0;
    $expert_videographer_offer_cat[]= 'select';
    foreach($expert_videographer_categories as $expert_videographer_category){
        if($expert_videographer_i==0){
            $expert_videographer_default = $expert_videographer_category->slug;
            $expert_videographer_i++;
        }
        $expert_videographer_offer_cat[$expert_videographer_category->slug] = $expert_videographer_category->name;
    }

    $wp_customize->add_setting(
    	'expert_videographer_offer_section_category',
    	array(
	        'default'   => 'uncategorized',
	        'sanitize_callback' => 'expert_videographer_sanitize_choices',
    	)
    );
    $wp_customize->add_control(
    	'expert_videographer_offer_section_category',
    	array(
	        'type'    => 'select',
	        'choices' => $expert_videographer_offer_cat,
	        'label' => __('Select Category','expert-videographer'),
	        'section' => 'expert_videographer_service_section',
    	)
    );

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

    // Add control for number of posts to show
    $wp_customize->add_control('expert_videographer_posts_to_show', array(
        'label'       => __('Number of Post to Show', 'expert-videographer'),
        'section'     => 'expert_videographer_service_section',
        'priority'    => 10,
        'type'        => 'number',
        'input_attrs' => array(
            'step' => 1,
            'min'  => 0,
            'max'  => 50,
        ),
    ));

    // Get the number of posts to show
    $expert_videographer_posts_to_show = get_theme_mod('expert_videographer_posts_to_show', 4);
    
    // Loop to create settings and controls for each post's price and star rating
    for ($expert_videographer_i = 1; $expert_videographer_i <= $expert_videographer_posts_to_show; $expert_videographer_i++) {

    	$wp_customize->add_setting('expert_videographer_serv_facebook_url' . $expert_videographer_i, array(
            'default' => '',
            'sanitize_callback' => 'esc_url_raw'
        ));

        $wp_customize->add_control('expert_videographer_serv_facebook_url' . $expert_videographer_i, array(
            'label'    => __('Add Facebook Link for Post ', 'expert-videographer') . $expert_videographer_i,
            'section'  => 'expert_videographer_service_section',
            'type'     => 'text',
            'priority' => 998,
        ));

        $wp_customize->add_setting('expert_videographer_serv_twitter_url' . $expert_videographer_i, array(
            'default' => '',
            'sanitize_callback' => 'esc_url_raw'
        ));

        $wp_customize->add_control('expert_videographer_serv_twitter_url' . $expert_videographer_i, array(
            'label'    => __('Add Twitter Link for Post', 'expert-videographer') . $expert_videographer_i,
            'section'  => 'expert_videographer_service_section',
            'type'     => 'text',
            'priority' => 998,
        ));

        $wp_customize->add_setting('expert_videographer_serv_insta_url' . $expert_videographer_i, array(
            'default' => '',
            'sanitize_callback' => 'esc_url_raw'
        ));

        $wp_customize->add_control('expert_videographer_serv_insta_url' . $expert_videographer_i, array(
            'label'    => __('Add Instagram Link for Post', 'expert-videographer') . $expert_videographer_i,
            'section'  => 'expert_videographer_service_section',
            'type'     => 'text',
            'priority' => 998,
        ));

        $wp_customize->add_setting('expert_videographer_serv_youtube_url' . $expert_videographer_i, array(
            'default' => '',
            'sanitize_callback' => 'esc_url_raw'
        ));

        $wp_customize->add_control('expert_videographer_serv_youtube_url' . $expert_videographer_i, array(
            'label'    => __('Add Youtube Link for Post', 'expert-videographer') . $expert_videographer_i,
            'section'  => 'expert_videographer_service_section',
            'type'     => 'text',
            'priority' => 998,
        ));
    }

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

}

add_action( 'customize_register', 'expert_videographer_blog_setting' );

// service selective refresh
function expert_videographer_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_videographer_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_videographer_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_videographer_blog_description_render_callback',
	
	) );	
	}

add_action( 'customize_register', 'expert_videographer_blog_section_partials' );

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

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

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