<?php
function expert_sports_coach_blog_setting( $wp_customize ) {

$wp_customize->register_control_type( 'Expert_Sports_Coach_Control_Upgrade' );

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

	// Slider Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_sports_coach_slider_setting' , 
			array(
			'default' => true,
			'sanitize_callback' => 'expert_sports_coach_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_sports_coach_slider_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-sports-coach' ),
			'section'     => 'expert_sports_coach_slider_section',
			'settings'    => 'expert_sports_coach_slider_setting',
			'type'        => 'checkbox'
		) 
	);
	
	for ( $expert_sports_coach_count = 1; $expert_sports_coach_count <= 3; $expert_sports_coach_count++ ) {

	// Add color scheme setting and control.
	$wp_customize->add_setting( 'expert_sports_coach_slider_page' . $expert_sports_coach_count, array(
		'sanitize_callback' => 'expert_sports_coach_sanitize_dropdown_pages'
	) );

	$wp_customize->add_control( 'expert_sports_coach_slider_page' . $expert_sports_coach_count, array(
		'label'    => __( 'Select Slide Image Page', 'expert-sports-coach' ),
		'section'  => 'expert_sports_coach_slider_section',
		'type'     => 'dropdown-pages'
	) );
	}

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

	$wp_customize->add_control( 
		'expert_sports_coach_slider_short_heading',
		array(
		    'label'   		=> __('Slider Top Text','expert-sports-coach'),
		    'section'		=> 'expert_sports_coach_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);

	$wp_customize->add_setting(
    	'expert_sports_coach_slider_btn_text',
    	array(
			'default' => 'Join Our Club',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'expert_sports_coach_slider_btn_text',
		array(
		    'label'   		=> __('Slider Button Text','expert-sports-coach'),
		    'section'		=> 'expert_sports_coach_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)  
	);

	$wp_customize->add_setting(
    	'expert_sports_coach_slider_btn_link',
    	array(
			'default' => '',
			'sanitize_callback' => 'esc_url_raw',
		)
	);
	$wp_customize->add_control( 
		'expert_sports_coach_slider_btn_link',
		array(
		    'label'   		=> __('Slider Button Link','expert-sports-coach'),
		    'section'		=> 'expert_sports_coach_slider_section',
			'type' 			=> 'url',
			'transport'         => $selective_refresh,
		)
	);

	$wp_customize->add_setting(
    	'expert_sports_coach_social_media_youtube',
    	array(
			'default' => '#',
			'sanitize_callback' => 'esc_url_raw',
		)
	);	
	$wp_customize->add_control( 
		'expert_sports_coach_social_media_youtube',
		array(
		    'label'   		=> __('Youtube URL','expert-sports-coach'),
		    'section'		=> 'expert_sports_coach_slider_section',
			'type' 			=> 'url',
			'transport'         => $selective_refresh,
		)  
	);

	$wp_customize->add_setting(
    	'expert_sports_coach_social_media_instagram',
    	array(
			'default' => '#',
			'sanitize_callback' => 'esc_url_raw',
		)
	);	
	$wp_customize->add_control( 
		'expert_sports_coach_social_media_instagram',
		array(
		    'label'   		=> __('Instagram URL','expert-sports-coach'),
		    'section'		=> 'expert_sports_coach_slider_section',
			'type' 			=> 'url',
			'transport'         => $selective_refresh,
		)  
	);

	$wp_customize->add_setting(
    	'expert_sports_coach_social_media_twitter',
    	array(
			'default' => '#',
			'sanitize_callback' => 'esc_url_raw',
		)
	);	
	$wp_customize->add_control( 
		'expert_sports_coach_social_media_twitter',
		array(
		    'label'   		=> __('Twitter URL','expert-sports-coach'),
		    'section'		=> 'expert_sports_coach_slider_section',
			'type' 			=> 'url',
			'transport'         => $selective_refresh,
		)  
	);	

	$wp_customize->add_setting(
    	'expert_sports_coach_social_media_pinterest',
    	array(
			'default' => '#',
			'sanitize_callback' => 'esc_url_raw',
		)
	);	
	$wp_customize->add_control( 
		'expert_sports_coach_social_media_pinterest',
		array(
		    'label'   		=> __('Pinterest URL','expert-sports-coach'),
		    'section'		=> 'expert_sports_coach_slider_section',
			'type' 			=> 'url',
			'transport'         => $selective_refresh,
		)  
	);

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

	/*=========================================
	product Section
	=========================================*/
	$wp_customize->add_section(
		'expert_sports_coach_our_products_section', array(
			'title' => esc_html__( 'Our Products Section', 'expert-sports-coach' ),
			'priority' => 13,
			'panel' => 'expert_sports_coach_frontpage_sections',
		)
	);

	// About Us Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_sports_coach_our_products_show_hide_section' , 
			array(
			'default' => '1',
			'sanitize_callback' => 'expert_sports_coach_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_sports_coach_our_products_show_hide_section', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-sports-coach' ),
			'section'     => 'expert_sports_coach_our_products_section',
			'settings'    => 'expert_sports_coach_our_products_show_hide_section',
			'type'        => 'checkbox'
		) 
	);

	// About Heading
	$wp_customize->add_setting( 
    	'expert_sports_coach_our_products_heading_section',
    	array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);	

	$wp_customize->add_control( 
		'expert_sports_coach_our_products_heading_section',
		array(
		    'label'   		=> __('Add Heading','expert-sports-coach'),
		    'section'		=> 'expert_sports_coach_our_products_section',
			'type' 			=> 'text',
		)
	);

	$expert_sports_coach_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
	);
	$expert_sports_coach_categories = get_categories($expert_sports_coach_args);
	$expert_sports_coach_cats = array();
	$expert_sports_coach_i = 0;
	foreach ($expert_sports_coach_categories as $expert_sports_coach_category) {
	    if ($expert_sports_coach_i == 0) {
	        $expert_sports_coach_default = $expert_sports_coach_category->slug;
	        $expert_sports_coach_i++;
	    }
	    $expert_sports_coach_cats[$expert_sports_coach_category->slug] = $expert_sports_coach_category->name;
	}

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

	$wp_customize->add_setting(
	    'expert_sports_coach_our_product_product_category',
	    array(
	        'default'           => $expert_sports_coach_default_value,
	        'sanitize_callback' => 'expert_sports_coach_sanitize_select',
	    )
	);

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

	$wp_customize->add_control(
	    'expert_sports_coach_our_product_product_category',
	    array(
	        'type'    => 'select',
	        'choices' => $expert_sports_coach_cats_with_none,
	        'label'   => __('Select Product Category', 'expert-sports-coach'),
	        'section' => 'expert_sports_coach_our_products_section',
	    )
	);

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

add_action( 'customize_register', 'expert_sports_coach_blog_setting' );

// service selective refresh
function expert_sports_coach_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_sports_coach_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_sports_coach_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_sports_coach_blog_description_render_callback',
	
	) );	
	}

add_action( 'customize_register', 'expert_sports_coach_blog_section_partials' );

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

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

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