<?php
function expert_fitness_trainer_blog_setting( $wp_customize ) {

$wp_customize->register_control_type( 'Expert_Fitness_Trainer_Control_Upgrade' );

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

	// Slider Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_fitness_trainer_slider_setting' , 
			array(
			'default' => true,
			'sanitize_callback' => 'expert_fitness_trainer_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_fitness_trainer_slider_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-fitness-trainer' ),
			'section'     => 'expert_fitness_trainer_slider_section',
			'settings'    => 'expert_fitness_trainer_slider_setting',
			'type'        => 'checkbox'
		) 
	);
	
	for ( $expert_fitness_trainer_count = 1; $expert_fitness_trainer_count <= 3; $expert_fitness_trainer_count++ ) {
		// Add color scheme setting and control.
		$wp_customize->add_setting( 'expert_fitness_trainer_slider_page' . $expert_fitness_trainer_count, array(
			'sanitize_callback' => 'expert_fitness_trainer_sanitize_dropdown_pages'
		) );

		$wp_customize->add_control( 'expert_fitness_trainer_slider_page' . $expert_fitness_trainer_count, array(
			'label'    => __( 'Select Slide Image Page', 'expert-fitness-trainer' ),
			'section'  => 'expert_fitness_trainer_slider_section',
			'type'     => 'dropdown-pages'
		) );
	}

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

	$wp_customize->add_control( 
		'expert_fitness_trainer_slider_short_heading',
		array(
		    'label'   		=> __('Slider Top Text','expert-fitness-trainer'),
		    'section'		=> 'expert_fitness_trainer_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);

	$expert_fitness_trainer_categories = get_categories();
	$expert_fitness_trainer_offer_cat = array('select' => 'Select');

	foreach ($expert_fitness_trainer_categories as $expert_fitness_trainer_category) {
	    $expert_fitness_trainer_offer_cat[$expert_fitness_trainer_category->slug] = $expert_fitness_trainer_category->name;
	}

	$wp_customize->add_setting('expert_fitness_trainer_about_catData', array(
	    'default' => 'uncategorized',
	    'sanitize_callback' => 'expert_fitness_trainer_sanitize_choices',
	));
	$wp_customize->add_control('expert_fitness_trainer_about_catData', array(
	    'type' => 'select',
	    'choices' => $expert_fitness_trainer_offer_cat,
	    'label' => __('Select a category to highlight Students photos', 'expert-fitness-trainer'),
	    'section' => 'expert_fitness_trainer_slider_section',
	));

	$wp_customize->add_setting('expert_fitness_trainer_student_count', array(
	    'default' => '',
	    'sanitize_callback' => 'sanitize_text_field',
	));
	$wp_customize->add_control('expert_fitness_trainer_student_count', array(
	    'label' => __('Add Student Count', 'expert-fitness-trainer'),
	    'section' => 'expert_fitness_trainer_slider_section',
	    'type' => 'text',
	));

	$wp_customize->add_setting(
    	'expert_fitness_trainer_slider_btn_text',
    	array(
			'default' => 'ENROLL NOW',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'expert_fitness_trainer_slider_btn_text',
		array(
		    'label'   		=> __('Enroll Button Text','expert-fitness-trainer'),
		    'section'		=> 'expert_fitness_trainer_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)  
	);

	$wp_customize->add_setting(
    	'expert_fitness_trainer_slider_btn_link',
    	array(
			'default' => '',
			'sanitize_callback' => 'esc_url_raw',
		)
	);
	$wp_customize->add_control( 
		'expert_fitness_trainer_slider_btn_link',
		array(
		    'label'   		=> __('Enroll Button Link','expert-fitness-trainer'),
		    'section'		=> 'expert_fitness_trainer_slider_section',
			'type' 			=> 'url',
			'transport'         => $selective_refresh,
		)
	);

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

	/*=========================================
	product Section
	=========================================*/
	$wp_customize->add_section(
		'expert_fitness_trainer_our_products_section', array(
			'title' => esc_html__( 'Our Products Section', 'expert-fitness-trainer' ),
			'priority' => 13,
			'panel' => 'expert_fitness_trainer_frontpage_sections',
		)
	);

	// About Us Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_fitness_trainer_our_products_show_hide_section' , 
			array(
			'default' => '1',
			'sanitize_callback' => 'expert_fitness_trainer_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_fitness_trainer_our_products_show_hide_section', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-fitness-trainer' ),
			'section'     => 'expert_fitness_trainer_our_products_section',
			'settings'    => 'expert_fitness_trainer_our_products_show_hide_section',
			'type'        => 'checkbox'
		) 
	);

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

	$wp_customize->add_control( 
		'expert_fitness_trainer_our_products_short_heading_section',
		array(
		    'label'   		=> __('Add Short Title','expert-fitness-trainer'),
		    'section'		=> 'expert_fitness_trainer_our_products_section',
			'type' 			=> 'text',
		)
	);

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

	$wp_customize->add_control( 
		'expert_fitness_trainer_our_products_heading_section',
		array(
		    'label'   		=> __('Add Heading','expert-fitness-trainer'),
		    'section'		=> 'expert_fitness_trainer_our_products_section',
			'type' 			=> 'text',
		)
	);

	$expert_fitness_trainer_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_fitness_trainer_categories = get_categories($expert_fitness_trainer_args);
	$expert_fitness_trainer_cats = array();
	$expert_fitness_trainer_i = 0;
	foreach ($expert_fitness_trainer_categories as $expert_fitness_trainer_category) {
	    if ($expert_fitness_trainer_i == 0) {
	        $expert_fitness_trainer_default = $expert_fitness_trainer_category->slug;
	        $expert_fitness_trainer_i++;
	    }
	    $expert_fitness_trainer_cats[$expert_fitness_trainer_category->slug] = $expert_fitness_trainer_category->name;
	}

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

	$wp_customize->add_setting(
	    'expert_fitness_trainer_our_product_product_category',
	    array(
	        'default'           => $expert_fitness_trainer_default_value,
	        'sanitize_callback' => 'expert_fitness_trainer_sanitize_select',
	    )
	);

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

	$wp_customize->add_control(
	    'expert_fitness_trainer_our_product_product_category',
	    array(
	        'type'    => 'select',
	        'choices' => $expert_fitness_trainer_cats_with_none,
	        'label'   => __('Select Product Category', 'expert-fitness-trainer'),
	        'section' => 'expert_fitness_trainer_our_products_section',
	    )
	);

	$wp_customize->add_setting(
    	'expert_fitness_trainer_product_btn_text',
    	array(
			'default' => '',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'expert_fitness_trainer_product_btn_text',
		array(
		    'label'   		=> __('Product Button Text','expert-fitness-trainer'),
		    'section'		=> 'expert_fitness_trainer_our_products_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)  
	);

	$wp_customize->add_setting(
    	'expert_fitness_trainer_product_btn_link',
    	array(
			'default' => '',
			'sanitize_callback' => 'esc_url_raw',
		)
	);
	$wp_customize->add_control( 
		'expert_fitness_trainer_product_btn_link',
		array(
		    'label'   		=> __('Product Button Link','expert-fitness-trainer'),
		    'section'		=> 'expert_fitness_trainer_our_products_section',
			'type' 			=> 'url',
			'transport'         => $selective_refresh,
		)
	);

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

add_action( 'customize_register', 'expert_fitness_trainer_blog_setting' );

// service selective refresh
function expert_fitness_trainer_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_fitness_trainer_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_fitness_trainer_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_fitness_trainer_blog_description_render_callback',
	
	) );	
	}

add_action( 'customize_register', 'expert_fitness_trainer_blog_section_partials' );

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

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

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