<?php
function expert_finance_manager_blog_setting( $wp_customize ) {

$wp_customize->register_control_type( 'Expert_Finance_Manager_Control_Upgrade' );

$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';
	$wp_customize->add_panel(
		'expert_finance_manager_frontpage_sections', array(
			'priority' => 1,
			'title' => esc_html__( 'Frontpage Sections', 'expert-finance-manager' ),
		)
	);
	
	/*=========================================
	Slider Section
	=========================================*/
	$wp_customize->add_section( 'expert_finance_manager_slider_section' , array(
    	'title'      => __( 'Slider Section', 'expert-finance-manager' ),
    	'priority' => 2,
		'panel' => 'expert_finance_manager_frontpage_sections'
	) );

	// Slider Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_finance_manager_slider_arrows' , 
			array(
			'default' => false,
			'sanitize_callback' => 'expert_finance_manager_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_finance_manager_slider_arrows', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-finance-manager' ),
			'section'     => 'expert_finance_manager_slider_section',
			'settings'    => 'expert_finance_manager_slider_arrows',
			'type'        => 'checkbox'
		) 
	);

	for ( $expert_finance_manager_count = 1; $expert_finance_manager_count <= 3; $expert_finance_manager_count++ ) {

		$wp_customize->add_setting( 'expert_finance_manager_slider_page' . $expert_finance_manager_count, array(
			'default'           => '',
			'sanitize_callback' => 'expert_finance_manager_sanitize_dropdown_pages'
		) );

		$wp_customize->add_control( 'expert_finance_manager_slider_page' . $expert_finance_manager_count, array(
			'label'    => __( 'Select Slide Image Page', 'expert-finance-manager' ),
			'section'  => 'expert_finance_manager_slider_section',
			'type'     => 'dropdown-pages'
		) );
	}

	$wp_customize->add_setting(
    	'expert_finance_manager_slider_btn_text',
    	array(
			'default' => 'Contact Us',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'expert_finance_manager_slider_btn_text',
		array(
		    'label'   		=> __('Slider Button Text 2','expert-finance-manager'),
		    'section'		=> 'expert_finance_manager_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)  
	);

	$wp_customize->add_setting(
    	'expert_finance_manager_slider_btn_link',
    	array(
			'default' => '#',
			'sanitize_callback' => 'esc_url_raw',
		)
	);
	$wp_customize->add_control( 
		'expert_finance_manager_slider_btn_link',
		array(
		    'label'   		=> __('Slider Button Link 2','expert-finance-manager'),
		    'section'		=> 'expert_finance_manager_slider_section',
			'type' 			=> 'url',
			'transport'         => $selective_refresh,
		)
	);

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

	// Service Section Settings
	$wp_customize->add_section('expert_finance_manager_service_section', array(
	  'title' => __('Our Team Section', 'expert-finance-manager'),
	  'panel' => 'expert_finance_manager_frontpage_sections',
	  'priority' => 14,
	));

	// About Us Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_finance_manager_show_hide_sec' , 
			array(
			'default' => false,
			'sanitize_callback' => 'expert_finance_manager_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	$wp_customize->add_control(
	'expert_finance_manager_show_hide_sec', 
		array(
			'label'	      => esc_html__( 'Show / Hide Service Section', 'expert-finance-manager' ),
			'section'     => 'expert_finance_manager_service_section',
			'settings'    => 'expert_finance_manager_show_hide_sec',
			'type'        => 'checkbox'
		) 
	);

	$wp_customize->add_setting('expert_finance_manager_serv_short_heading',array(
		'default'=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));
	$wp_customize->add_control('expert_finance_manager_serv_short_heading',array(
		'label'	=> __('Add short Heading','expert-finance-manager'),
		'section'=> 'expert_finance_manager_service_section',
		'type'=> 'text'
	));
	
	$wp_customize->add_setting('expert_finance_manager_featured_section_title', array(
	  'default' => '',
	  'sanitize_callback' => 'sanitize_text_field'
	));
	$wp_customize->add_control('expert_finance_manager_featured_section_title', array(
	  'label' => __('Add Heading', 'expert-finance-manager'),
	  'section' => 'expert_finance_manager_service_section',
	  'type' => 'text'
	));

	$expert_finance_manager_categories = get_categories();
	$cats = array();
	$expert_finance_manager_i = 0;
	$expert_finance_manager_offer_cat[] = 'select';
	foreach ($expert_finance_manager_categories as $expert_finance_manager_category) {
	  if ($expert_finance_manager_i == 0) {
	    $expert_finance_manager_default = $expert_finance_manager_category->slug;
	    $expert_finance_manager_i++;
	  }
	  $expert_finance_manager_offer_cat[$expert_finance_manager_category->slug] = $expert_finance_manager_category->name;
	}

	$wp_customize->add_setting('expert_finance_manager_featured_section_category', array(
	  'default' => 'uncategorized',
	  'sanitize_callback' => 'expert_finance_manager_sanitize_choices',
	));
	$wp_customize->add_control('expert_finance_manager_featured_section_category', array(
	  'type' => 'select',
	  'choices' => $expert_finance_manager_offer_cat,
	  'label' => __('Select Category', 'expert-finance-manager'),
	  'section' => 'expert_finance_manager_service_section',
	));

	$wp_customize->add_setting('expert_finance_manager_num_posts', array(
	  'default' => 4,
	  'sanitize_callback' => 'absint',
	));
	$wp_customize->add_control('expert_finance_manager_num_posts', array(
	  'label' => __('Number of Posts to Show', 'expert-finance-manager'),
	  'section' => 'expert_finance_manager_service_section',
	  'type' => 'number',
	));

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

    	$wp_customize->add_setting('expert_finance_manager_team_role' . $expert_finance_manager_i, array(
            'default' => 'Accountant',
            'sanitize_callback' => 'sanitize_text_field'
        ));
        $wp_customize->add_control('expert_finance_manager_team_role' . $expert_finance_manager_i, array(
            'label'    => __('Add Role for Team Member ', 'expert-finance-manager') . $expert_finance_manager_i,
            'section'  => 'expert_finance_manager_service_section',
            'type'     => 'text',
            'priority' => 998,
        ));
    }

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

add_action( 'customize_register', 'expert_finance_manager_blog_setting' );

// service selective refresh
function expert_finance_manager_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_finance_manager_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_finance_manager_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_finance_manager_blog_description_render_callback',
	
	) );	
	}

add_action( 'customize_register', 'expert_finance_manager_blog_section_partials' );

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

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

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