<?php
/**
 * Manage the function for customizer selective refresh
 * 
 * @package Blogbuster
 */

if ( ! function_exists( 'blogbuster_customizer_selective_refresh' ) ) :

	/**
	 * function about control partial refresh for the customizer preview
	 * 
	 * @since 1.0.0
	 */
	function blogbuster_customizer_selective_refresh( $wp_customize ) {

		// Abort if selective refresh is not available.
	    if ( ! isset( $wp_customize->selective_refresh ) ) {
	        return;
	    }

	    //featured items section title -- Frontpage Settings > Featured
	    $wp_customize->selective_refresh->add_partial( 'blogbuster_front_featured_section_title',
	        array(
	            'selector'        => '.mt-front-featured-wrapper .mt-content-title',
	            'render_callback' => 'blogbuster_customize_partial_front_featured_section_title',
	        )
	    );

	    //scroll top -- General Settings > Scroll Top
	    $wp_customize->selective_refresh->add_partial( 'blogbuster_scroll_top_enable',
	        array(
	            'selector'        => '#mt-scrollup',
	            'render_callback' => 'blogbuster_scroll_top_rc',
	        )
	    );

	    //copyright info -- Footer Settings > Bottom Area
	    $wp_customize->selective_refresh->add_partial( 'blogbuster_footer_copyright_info',
	        array(
	            'selector'        => '.site-info .copyright-content',
	            'render_callback' => 'blogbuster_customize_partial_copyright_info',
	        )
	    );

	}

endif;

add_action( 'customize_register', 'blogbuster_customizer_selective_refresh' );

/**
 * Render the value of featured section title for the selective refresh partial.
 *
 * @return void
 */
function blogbuster_customize_partial_front_featured_section_title() {
	$copyright_info = blogbuster_get_customizer_option_value( 'blogbuster_front_featured_section_title' );
	return $copyright_info;
}

/**
 * Render the value of copyright info for the selective refresh partial.
 *
 * @return void
 */
function blogbuster_customize_partial_copyright_info() {
	$copyright_info = blogbuster_get_customizer_option_value( 'blogbuster_footer_copyright_info' );
	return $copyright_info;
}

/**
 * Render the value of scroll top toggle for the selective refresh partial.
 *
 * @return void
 */
function blogbuster_scroll_top_rc() {
	$scroll_top_enable = blogbuster_get_customizer_option_value( 'blogbuster_scroll_top_enable' );
	return $scroll_top_enable;
}