<?php
/**
 * Blog Bee Pro Theme Customizer
 *
 * @package Blog Bee
 */
use BBE\Customizer\Section\BBE_Customzie_Section as BBE_Customzie_Section;
use BBE\Customizer\Theme_Defaults as Theme_Defaults;
/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function blog_bee_customize_register( $wp_customize ) {
	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->default  = esc_html__( 'Lorem Ipsum', 'blog-bee' );

	/**
	 * Customizer base class
	 */
	require_once get_template_directory() . '/inc/customizer/custom-controls/base.php';

	$wp_customize->register_section_type( BBE_Customzie_Section::class );

	/**
	 * Autoload all files from custom-controls filder
	*/
	blog_bee_autoload_files( get_template_directory() . '/inc/customizer/custom-controls' );

	if ( isset( $wp_customize->selective_refresh ) ) {
		$wp_customize->selective_refresh->add_partial(
			'blogname',
			array(
				'selector'        => '.site-title a',
				'render_callback' => 'blog_bee_customize_partial_blogname',
			)
		);
		$wp_customize->selective_refresh->add_partial(
			'blogdescription',
			array(
				'selector'        => '.site-description',
				'render_callback' => 'blog_bee_customize_partial_blogdescription',
				'settings'	=>	[ 'site_tagline_option', 'blogdescription' ]
			)
		);
	}
}
add_action( 'customize_register', 'blog_bee_customize_register' );

/**
 * Render the site title for the selective refresh partial.
 *
 * @return void
 */
function blog_bee_customize_partial_blogname() {
	bloginfo( 'name' );
}

/**
 * Render the site tagline for the selective refresh partial.
 *
 * @return void
 */
function blog_bee_customize_partial_blogdescription() {
	$tagline_option = Theme_Defaults::get_theme_option( 'site_tagline_option' );
	if( $tagline_option ) echo '<p class="site-description">'. esc_html( get_bloginfo( 'description' ) ) .'</p>';
}