<?php
/**
 * Social_Charity Theme Customizer
 *
 * @package Social_Charity
 */

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */

use WPTRT\Customize\Section\Button;

function social_charity_customize_register( $wp_customize ) {
	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
	$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';

	if ( isset( $wp_customize->selective_refresh ) ) {
		$wp_customize->selective_refresh->add_partial( 'blogname', array(
			'selector'        => '.site-title a',
			'render_callback' => 'social_charity_customize_partial_blogname',
		) );
		$wp_customize->selective_refresh->add_partial( 'blogdescription', array(
			'selector'        => '.site-description',
			'render_callback' => 'social_charity_customize_partial_blogdescription',
		) );
	}

	//Upgrade to Pro
	$wp_customize->register_section_type( Button::class );

	// Register sections.
	$wp_customize->add_section(
		new Button(
			$wp_customize,
			'social_charity_pro',
			array(
				'title'    => esc_html__( 'Go Pro', 'social-charity' ),
				'button_text' => esc_html__( 'Buy Social Charity Pro', 'social-charity' ),
				'button_url'  => 'http://html5wp.com/downloads/social-charity-pro/',
				'priority' => 1,
			)
		)
	);
}
add_action( 'customize_register', 'social_charity_customize_register' );

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

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

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function social_charity_customize_preview_js() {
	wp_enqueue_script( 'social_charity-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20151215', true );
}
add_action( 'customize_preview_init', 'social_charity_customize_preview_js' );


function social_charity_customize_backend_scripts() {
	$version = wp_get_theme()->get( 'Version' );

	wp_enqueue_script(
		'social-charity-customize-section-button',
		get_theme_file_uri( 'inc/upgrade-to-pro/public/js/customize-controls.js' ),
		[ 'customize-controls' ],
		$version,
		true
	);

	wp_enqueue_style(
		'social-charity-customize-section-button',
		get_theme_file_uri( 'inc/upgrade-to-pro/public/css/customize-controls.css' ),
		[ 'customize-controls' ],
 		$version
	);
}
add_action( 'customize_controls_enqueue_scripts', 'social_charity_customize_backend_scripts', 10 );

/*----------------------------------------------------------------------------------------------------------------------------------------*/
/**
 * Load customizer required panels.
 */

require get_template_directory() . '/inc/customizer/general-panel.php';

require get_template_directory() . '/inc/customizer/header-panel.php';
require get_template_directory() . '/inc/customizer/frontpage-panel.php';
require get_template_directory() . '/inc/customizer/template-panel.php';
require get_template_directory() . '/inc/customizer/footer-panel.php';

require get_template_directory() . '/inc/customizer/customizer-sanitize.php';
require get_template_directory() . '/inc/customizer/customizer-classes.php';


// Autoloader
include get_theme_file_path( 'inc/upgrade-to-pro/src/Loader.php' );

$social_charity_loader = new \WPTRT\Autoload\Loader();

$social_charity_loader->add( 'WPTRT\\Customize\\Section', get_theme_file_path( 'inc/upgrade-to-pro/src' ) );

$social_charity_loader->register();