<?php
function newsxo_selective_refresh( $wp_customize ) {

	if (isset($wp_customize->selective_refresh)) {
		$wp_customize->selective_refresh->add_partial('blogname', array(
            'selector'        => '.site-title a , .site-title-footer a',
            'render_callback' => 'newsxo_customize_partial_blogname',
        ));
        $wp_customize->selective_refresh->add_partial('blogdescription', array(
            'selector'        => '.site-description , .site-description-footer',
            'render_callback' => 'newsxo_customize_partial_blogdescription',
        ));
		$wp_customize->selective_refresh->add_partial('custom_logo', array(
			'selector'        => '.site-logo', 
			'render_callback' => 'custom_logo_selective_refresh'
		));

        $wp_customize->selective_refresh->add_partial('newsxo_scrollup_enable', array(
            'selector'        => '.bs_upscr',
        ));

        $wp_customize->selective_refresh->add_partial('you_missed_title', array(
            'selector'          => '.missed .bs-widget-title',
            'render_callback'   => 'newsxo_customize_partial_you_missed_title',
        ));

        $wp_customize->selective_refresh->add_partial('sidebar_menu', array(
            'selector'        => '.navbar-wp [data-bs-toggle=offcanvas]',
            'render_callback' => 'newsxo_customize_partial_sidebar_menu',
        ));
        $wp_customize->selective_refresh->add_partial('newsxo_related_post_title', array(
            'selector'        => '.bs-related-post-info .mb-3 .title',
            'render_callback' => 'newsxo_customize_partial_newsxo_related_post_title',
        ));

        $wp_customize->selective_refresh->add_partial('newsxo_menu_search', array(
            'selector'        => '.desk-header .right-nav a',
            'render_callback' => 'newsxo_customize_partial_newsxo_menu_search',
        ));

        $wp_customize->selective_refresh->add_partial('newsxo_lite_dark_switcher', array(
            'selector'        => '.switch .slider',    
        ));

        $wp_customize->selective_refresh->add_partial('single_post_meta', array(
            'selector'        => '.bs-blog-post .bs-header .bs-blog-meta ',
        )); 
        $wp_customize->selective_refresh->add_partial('newsxo_drop_caps_enable', array(
            'selector'        => '.content-right .bs-blog-post .bs-blog-meta', 
        ));   
        $wp_customize->selective_refresh->add_partial('hide_copyright', array(
            'selector'        => '.bs-footer-copyright .container', 
        ));   
        $wp_customize->selective_refresh->add_partial('newsxo_main_banner_section_background_image', array(
            'selector'        => '.homemain .bs-blog-post.three .bs-blog-meta', 
        ));
        $wp_customize->selective_refresh->add_partial('newsxo_archive_page_layout', array(
            'selector'        => '.index-class .row, .archive-class > .container > .row', 
            'render_callback' => 'newsxo_customize_partial_archive_page'
        ));    
        $wp_customize->selective_refresh->add_partial('newsxo_single_page_layout', array(
            'selector'        => '.single-class > .container .page-entry-title + .row', 
            'render_callback' => 'newsxo_customize_partial_single_page'
        ));    
        $wp_customize->selective_refresh->add_partial('newsxo_page_layout', array(
            'selector'        => '.page-class > .container > .row', 
            'render_callback' => 'newsxo_customize_partial_page'
        ));
        $wp_customize->selective_refresh->add_partial('header_date_enable', array(
            'selector'        => '.bs-head-detail .top-date',
        ));
        $wp_customize->selective_refresh->add_partial('social_icon_header_enable', array(
            'selector'        => '.bs-head-detail .bs-social',
        ));
        $wp_customize->selective_refresh->add_partial('footer_social_icon_enable', array(
            'selector'        => '.bs-footer-bottom-area .bs-social',
        ));
        $wp_customize->selective_refresh->add_partial('breaking_news_title', array(
            'selector'        => '.bs-latest-news .bn_title .title i',
        ));
        $wp_customize->selective_refresh->add_partial('newsxo_header_topbar_repeater', array(
			'selector'        => '.bs-head-detail .align-center .tobbar-right',
			'render_callback' => 'newsxo_partial_header_topbar',
		));
		$wp_customize->selective_refresh->add_partial('newsxo_header_mid_repeater', array(
			'selector'        => '.bs-menu-full .inner .main',
			'render_callback' => 'newsxo_partial_header_mid',
		));
		$wp_customize->selective_refresh->add_partial('newsxo_header_bottom_repeater', array(
			'selector'        => '.bs-menu-bottom .container .row',
			'render_callback' => 'newsxo_partial_header_bottom',
		));
		$wp_customize->selective_refresh->add_partial('newsxo_header_extra_repeater', array(
			'selector'        => '.bs-head-extra .row.align-center',
			'render_callback' => 'newsxo_partial_header_extra',
		));
		$wp_customize->selective_refresh->add_partial('newsxo_footer_top_repeater', array(
			'selector'        => '.bs-footer-widget-area .row',
			'render_callback' => 'newsxo_partial_footer_top',
		));
		$wp_customize->selective_refresh->add_partial('newsxo_footer_mid_repeater', array(
			'selector'        => '.bs-footer-bottom-area .row.align-center',
			'render_callback' => 'newsxo_partial_footer_mid',
		));
		$wp_customize->selective_refresh->add_partial('newsxo_footer_bottom_repeater', array(
			'selector'        => '.bs-footer-copyright .row.align-center',
			'render_callback' => 'newsxo_partial_footer_bottom',
		));
	}
}
add_action( 'customize_register', 'newsxo_selective_refresh' );
/**
 * Render the site title for the selective refresh partial.
 *
 * @return void
 */
function newsxo_customize_partial_blogname() {
	bloginfo('name');
}

/**
 * Render the site tagline for the selective refresh partial.
 *
 * @return void
 */
function newsxo_customize_partial_blogdescription() {
	bloginfo('description');
}

function custom_logo_selective_refresh() {
	if( get_theme_mod( 'custom_logo' ) === "" ) return;
	echo '<div id="site-logo">'.the_custom_logo().'</div>';
}

function newsxo_customize_partial_footer_social_icon_enable() {
    return get_theme_mod( 'newsxo_social_icons' ); 
}

function newsxo_customize_partial_newsxo_related_post_title() {
    return get_theme_mod( 'newsxo_related_post_title' ); 
}


function newsxo_customize_partial_you_missed_title() {
	if( get_theme_mod( 'you_missed_title' ) === "" ) return;
	echo '<h2 class="title">'.get_theme_mod( 'you_missed_title' ).'</h2>';
}

function newsxo_customize_partial_sidebar_menu() {
    return get_theme_mod( 'sidebar_menu' ); 
}

function newsxo_customize_partial_newsxo_menu_subscriber() {
    return get_theme_mod( 'newsxo_menu_subscriber' ); 
}

function newsxo_customize_partial_archive_page() {
    do_action('newsxo_action_main_content_layouts');
}

function newsxo_customize_partial_single_page() {
    do_action('newsxo_action_single_main_content_layouts');
}

function newsxo_customize_partial_page() {
    get_template_part('template-parts/sections/page','data'); 
}

function newsxo_partial_header_topbar() {
	return newsxo_output_repeater('newsxo_header_topbar_repeater');
}

function newsxo_partial_header_mid() {
	return newsxo_output_repeater('newsxo_header_mid_repeater');
}

function newsxo_partial_header_bottom() {
	return newsxo_output_repeater('newsxo_header_bottom_repeater');
}

function newsxo_partial_header_extra() {
	return newsxo_output_repeater('newsxo_header_extra_repeater');
}

function newsxo_partial_footer_top() {
	return newsxo_output_repeater('newsxo_footer_top_repeater');
}

function newsxo_partial_footer_mid() {
	return newsxo_output_repeater('newsxo_footer_mid_repeater');
}

function newsxo_partial_footer_bottom() {
	return newsxo_output_repeater('newsxo_footer_bottom_repeater');
}