<?php
function expert_makeup_stylist_blog_setting( $wp_customize ) {

$wp_customize->register_control_type( 'Expert_Makeup_Stylist_Control_Upgrade' );

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

	// Slider Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_makeup_stylist_slider_setting' , 
			array(
			'default' => false,
			'sanitize_callback' => 'expert_makeup_stylist_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_makeup_stylist_slider_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-makeup-stylist' ),
			'section'     => 'expert_makeup_stylist_slider_section',
			'settings'    => 'expert_makeup_stylist_slider_setting',
			'type'        => 'checkbox'
		) 
	);
	
	// Slider 1
	$wp_customize->add_setting( 
    	'expert_makeup_stylist_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_makeup_stylist_slider1',
		array(
		    'label'   		=> __('Slider 1','expert-makeup-stylist'),
		    'section'		=> 'expert_makeup_stylist_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);		

	// Slider 2
	$wp_customize->add_setting(
    	'expert_makeup_stylist_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_makeup_stylist_slider2',
		array(
		    'label'   		=> __('Slider 2','expert-makeup-stylist'),
		    'section'		=> 'expert_makeup_stylist_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);

	// Slider 3
	$wp_customize->add_setting(
    	'expert_makeup_stylist_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_makeup_stylist_slider3',
		array(
		    'label'   		=> __('Slider 3','expert-makeup-stylist'),
		    'section'		=> 'expert_makeup_stylist_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);

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

	$wp_customize->add_control( 
		'expert_makeup_stylist_slider_text',
		array(
		    'label'   		=> __('Slider Text','expert-makeup-stylist'),
		    'section'		=> 'expert_makeup_stylist_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);

	$wp_customize->add_setting(
		'expert_makeup_stylist_slider_call',
		array(
			'default'=> '',
			'sanitize_callback'	=> 'expert_makeup_stylist_sanitize_phone_number'
		)
	);

	$wp_customize->add_control(
		'expert_makeup_stylist_slider_call',array(
			'label'	=> __('Add Phone Number','expert-makeup-stylist'),
			'section'=> 'expert_makeup_stylist_slider_section',
			'type'=> 'text'
		)
	);

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

	/*=========================================
	product Section
	=========================================*/
	$wp_customize->add_section(
		'expert_makeup_stylist_our_products_section', array(
			'title' => esc_html__( 'Our Products Section', 'expert-makeup-stylist' ),
			'priority' => 13,
			'panel' => 'expert_makeup_stylist_frontpage_sections',
		)
	);

	// About Us Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'expert_makeup_stylist_our_products_show_hide_section' , 
			array(
			'default' => 0,
			'sanitize_callback' => 'expert_makeup_stylist_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'expert_makeup_stylist_our_products_show_hide_section', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'expert-makeup-stylist' ),
			'section'     => 'expert_makeup_stylist_our_products_section',
			'settings'    => 'expert_makeup_stylist_our_products_show_hide_section',
			'type'        => 'checkbox'
		) 
	);

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

	$wp_customize->add_control( 
		'expert_makeup_stylist_our_products_heading_section',
		array(
		    'label'   		=> __('Add Heading','expert-makeup-stylist'),
		    'section'		=> 'expert_makeup_stylist_our_products_section',
			'type' 			=> 'text',
		)
	);

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

	$wp_customize->add_control( 
		'expert_makeup_stylist_our_products_content_section',
		array(
		    'label'   		=> __('Add Main Content','expert-makeup-stylist'),
		    'section'		=> 'expert_makeup_stylist_our_products_section',
			'type' 			=> 'text',
		)
	);

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

	$wp_customize->add_control( 
		'expert_makeup_stylist_detail_content',
		array(
		    'label'   		=> __('Add Details','expert-makeup-stylist'),
		    'section'		=> 'expert_makeup_stylist_our_products_section',
			'type' 			=> 'text',
		)
	);

	// About Button Text
	$wp_customize->add_setting( 
    	'expert_makeup_stylist_our_products_btn_section',
    	array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control( 
		'expert_makeup_stylist_our_products_btn_section',
		array(
		    'label'   		=> __('About Button Text','expert-makeup-stylist'),
		    'section'		=> 'expert_makeup_stylist_our_products_section',
			'type' 			=> 'text',
		)
	);

	// About Button Link
	$wp_customize->add_setting( 
    	'expert_makeup_stylist_our_products_btn_link_section',
    	array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control( 
		'expert_makeup_stylist_our_products_btn_link_section',
		array(
		    'label'   		=> __('About Button Link','expert-makeup-stylist'),
		    'section'		=> 'expert_makeup_stylist_our_products_section',
			'type' 			=> 'text',
		)
	);

	$expert_makeup_stylist_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_makeup_stylist_categories = get_categories($expert_makeup_stylist_args);
$expert_makeup_stylist_cats = array();
$expert_makeup_stylist_i = 0;
foreach ($expert_makeup_stylist_categories as $expert_makeup_stylist_category) {
    if ($expert_makeup_stylist_i == 0) {
        $expert_makeup_stylist_default = $expert_makeup_stylist_category->slug;
        $expert_makeup_stylist_i++;
    }
    $expert_makeup_stylist_cats[$expert_makeup_stylist_category->slug] = $expert_makeup_stylist_category->name;
}

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

$wp_customize->add_setting(
    'expert_makeup_stylist_our_product_product_category',
    array(
        'default'           => $expert_makeup_stylist_default_value,
        'sanitize_callback' => 'expert_makeup_stylist_sanitize_select',
    )
);

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

$wp_customize->add_control(
    'expert_makeup_stylist_our_product_product_category',
    array(
        'type'    => 'select',
        'choices' => $expert_makeup_stylist_cats_with_none,
        'label'   => __('Select Product Category', 'expert-makeup-stylist'),
        'section' => 'expert_makeup_stylist_our_products_section',
    )
);

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

}

add_action( 'customize_register', 'expert_makeup_stylist_blog_setting' );

// service selective refresh
function expert_makeup_stylist_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_makeup_stylist_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_makeup_stylist_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_makeup_stylist_blog_description_render_callback',
	
	) );	
	}

add_action( 'customize_register', 'expert_makeup_stylist_blog_section_partials' );

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

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

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