<?php
/**
 * Customizer bootstrap.
 *
 * @package ttsunsolar
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

require_once TTSUNSOLAR_DIR . '/solarcustom/solarcustom-header.php';
require_once TTSUNSOLAR_DIR . '/solarcustom/solarcustom-banner.php';
require_once TTSUNSOLAR_DIR . '/solarcustom/solarcustom-inner-banner.php';
require_once TTSUNSOLAR_DIR . '/solarcustom/solarcustom-services.php';
require_once TTSUNSOLAR_DIR . '/solarcustom/solarcustom-footer.php';
require_once TTSUNSOLAR_DIR . '/solarcustom/solarcustom-copyright.php';

/**
 * Load pro section class when Customizer is available.
 *
 * @param WP_Customize_Manager $wp_customize Customizer.
 */
function ttsunsolar_customize_register_custom_controls( $wp_customize ) {
	require_once TTSUNSOLAR_DIR . '/solarcustom/proupgrade/solarcustom-sectionpro.php';
	$wp_customize->register_section_type( 'Ttsunsolar_Customize_Section_Pro' );
}
add_action( 'customize_register', 'ttsunsolar_customize_register_custom_controls', 9 );

/**
 * Enqueue Customizer controls assets.
 */
function ttsunsolar_customize_controls_assets() {
	wp_enqueue_script(
		'ttsunsolar-customize-controls',
		TTSUNSOLAR_URI . '/solarcustom/proupgrade/solarcustom-customize-controls.js',
		array( 'customize-controls' ),
		TTSUNSOLAR_VERSION,
		true
	);
	wp_enqueue_style(
		'ttsunsolar-customize-controls',
		TTSUNSOLAR_URI . '/solarcustom/proupgrade/solarcustom-customize-controls.css',
		array(),
		TTSUNSOLAR_VERSION
	);
}
add_action( 'customize_controls_enqueue_scripts', 'ttsunsolar_customize_controls_assets' );

/**
 * Enqueue Customizer preview script (live site title / tagline).
 */
function ttsunsolar_customize_preview_assets() {
	wp_enqueue_script(
		'ttsunsolar-customize-preview',
		TTSUNSOLAR_URI . '/solarcustom/solarcustom-preview.js',
		array( 'customize-preview' ),
		TTSUNSOLAR_VERSION,
		true
	);
}
add_action( 'customize_preview_init', 'ttsunsolar_customize_preview_assets' );

/**
 * Register Customizer panel, sections and controls.
 *
 * @param WP_Customize_Manager $wp_customize Customizer.
 */
function ttsunsolar_customize_register( $wp_customize ) {
	$wp_customize->add_section(
		new Ttsunsolar_Customize_Section_Pro(
			$wp_customize,
			'ttsunsolar_go_pro',
			array(
				'priority' => 1,
				'title'    => esc_html__( 'TTSun Solar Pro', 'ttsunsolar' ),
				'pro_text' => esc_html__( 'Upgrade To Pro', 'ttsunsolar' ),
				'pro_url'  => TTSUNSOLAR_PRO_URL,
			)
		)
	);

	$wp_customize->add_panel(
		'ttsunsolar_panel',
		array(
			'title'       => esc_html__( 'TTSun Solar Theme Options', 'ttsunsolar' ),
			'description' => esc_html__( 'Customize header, homepage banner, inner page banner, Solar Services, footer, and copyright.', 'ttsunsolar' ),
			'priority'    => 25,
		)
	);

	ttsunsolar_customizer_header( $wp_customize );
	ttsunsolar_customizer_banner( $wp_customize );
	ttsunsolar_customizer_inner_banner( $wp_customize );
	ttsunsolar_customizer_services( $wp_customize );
	ttsunsolar_customizer_footer( $wp_customize );
	ttsunsolar_customizer_copyright( $wp_customize );
}
add_action( 'customize_register', 'ttsunsolar_customize_register' );
