<?php
function led_tv_blog_setting( $wp_customize ) {

$wp_customize->register_control_type( 'Led_TV_Control_Upgrade' );

$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';
	$wp_customize->add_panel(
		'led_tv_frontpage_sections', array(
			'priority' => 1,
			'title' => esc_html__( 'Frontpage Sections', 'led-tv' ),
		)
	);
	
	/*=========================================
	Slider Section
	=========================================*/
	$wp_customize->add_section(
		'led_tv_slider_section', array(
			'title' => esc_html__( 'Slider Section', 'led-tv' ),
			'priority' => 13,
			'panel' => 'led_tv_frontpage_sections',
		)
	);

	// Slider Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'led_tv_slider_setting' , 
			array(
			'default' => true,
			'sanitize_callback' => 'led_tv_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'led_tv_slider_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'led-tv' ),
			'section'     => 'led_tv_slider_section',
			'settings'    => 'led_tv_slider_setting',
			'type'        => 'checkbox'
		) 
	);
	
	// Slider 1
	$wp_customize->add_setting( 
    	'led_tv_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( 
		'led_tv_slider1',
		array(
		    'label'   		=> __('Slider 1','led-tv'),
		    'section'		=> 'led_tv_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);		

	// Slider 2
	$wp_customize->add_setting(
    	'led_tv_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( 
		'led_tv_slider2',
		array(
		    'label'   		=> __('Slider 2','led-tv'),
		    'section'		=> 'led_tv_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);

	// Slider 3
	$wp_customize->add_setting(
    	'led_tv_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( 
		'led_tv_slider3',
		array(
		    'label'   		=> __('Slider 3','led-tv'),
		    'section'		=> 'led_tv_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);

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

	$wp_customize->add_control( 
		'led_tv_slider_text',
		array(
		    'label'   		=> __('Slider Text','led-tv'),
		    'section'		=> 'led_tv_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);

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

	$wp_customize->add_control( 
		'led_tv_slider_text_one',
		array(
		    'label'   		=> __('Slider Text 1','led-tv'),
		    'section'		=> 'led_tv_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);

	$wp_customize->add_setting( 'led_tv_upgrade_page_settings_1',
        array(
            'sanitize_callback' => 'sanitize_text_field'
        )
    );
    $wp_customize->add_control( new Led_TV_Control_Upgrade(
        $wp_customize, 'led_tv_upgrade_page_settings_1',
            array(
                'priority'      => 200,
                'section'       => 'led_tv_slider_section',
                'settings'      => 'led_tv_upgrade_page_settings_1',
                'label'         => __( 'LED TV Pro comes with additional features.', 'led-tv' ),
                'choices'       => array( __( '15+ Ready-Made Sections', 'led-tv' ), __( 'One-Click Demo Import', 'led-tv' ), __( 'WooCommerce Integrated', 'led-tv' ), __( 'Drag & Drop Section Reordering', 'led-tv' ),__( 'Advanced Typography Control', 'led-tv' ),__( 'Intuitive Customization Options', 'led-tv' ),__( '24/7 Support', 'led-tv' ), )
            )
        )
    ); 

	/*=========================================
	Best Seller Product Section
	=========================================*/
	$wp_customize->add_section(
		'led_tv_product_section', array(
			'title' => esc_html__( 'Our Product Section', 'led-tv' ),
			'priority' => 13,
			'panel' => 'led_tv_frontpage_sections',
		)
	);

	$wp_customize->add_setting( 
		'led_tv_our_product_setting' , 
			array(
			'default' => true,
			'sanitize_callback' => 'led_tv_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'led_tv_our_product_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'led-tv' ),
			'section'     => 'led_tv_product_section',
			'settings'    => 'led_tv_our_product_setting',
			'type'        => 'checkbox'
		) 
	);

	// short heading
	$wp_customize->add_setting( 
    	'led_tv_our_product_short_heading',
    	array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'sanitize_text_field',
			'priority'      => 1,
		)
	);	

	$wp_customize->add_control( 
		'led_tv_our_product_short_heading',
		array(
		    'label'   		=> __('Short Heading','led-tv'),
		    'section'		=> 'led_tv_product_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);

	// heading
	$wp_customize->add_setting( 
    	'led_tv_our_product_heading',
    	array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'sanitize_text_field',
			'priority'      => 1,
		)
	);	

	$wp_customize->add_control( 
		'led_tv_our_product_heading',
		array(
		    'label'   		=> __('Heading','led-tv'),
		    'section'		=> 'led_tv_product_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);

	$led_tv_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
	);
	$led_tv_categories = get_categories( $led_tv_args );
	$led_tv_cats = array();
	$led_tv_i = 0;
	foreach($led_tv_categories as $led_tv_category){
		if($led_tv_i==0){
				$led_tv_default = $led_tv_category->slug;
				$led_tv_i++;
		}
		$led_tv_cats[$led_tv_category->slug] = $led_tv_category->name;
	}

	$wp_customize->add_setting(
		'led_tv_our_product_product_category',array(
			'default' => 'product_cat1',
			'sanitize_callback' => 'led_tv_sanitize_select',
		)
	);

	$wp_customize->add_control(
		'led_tv_our_product_product_category',array(
		'type'    => 'select',
		'choices' => $led_tv_cats,
		'label' => __('Select Product Category','led-tv'),
		'section' => 'led_tv_product_section',
		)
	);

	$wp_customize->add_setting( 'led_tv_upgrade_page_settings_2',
        array(
            'sanitize_callback' => 'sanitize_text_field'
        )
    );
    $wp_customize->add_control( new Led_TV_Control_Upgrade(
        $wp_customize, 'led_tv_upgrade_page_settings_2',
            array(
                'priority'      => 200,
                'section'       => 'led_tv_product_section',
                'settings'      => 'led_tv_upgrade_page_settings_2',
                'label'         => __( 'LED TV Pro comes with additional features.', 'led-tv' ),
                'choices'       => array( __( '15+ Ready-Made Sections', 'led-tv' ), __( 'One-Click Demo Import', 'led-tv' ), __( 'WooCommerce Integrated', 'led-tv' ), __( 'Drag & Drop Section Reordering', 'led-tv' ),__( 'Advanced Typography Control', 'led-tv' ),__( 'Intuitive Customization Options', 'led-tv' ),__( '24/7 Support', 'led-tv' ), )
            )
        )
    ); 
}

add_action( 'customize_register', 'led_tv_blog_setting' );

// service selective refresh
function led_tv_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'  => 'led_tv_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'  => 'led_tv_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'  => 'led_tv_blog_description_render_callback',
	
	) );	
	}

add_action( 'customize_register', 'led_tv_blog_section_partials' );

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

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

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