<?php
/**
 * Yaatra Theme Customizer
 *
 * This file is responsible for adding theme customization options and settings
 * to the WordPress Customizer, allowing users to personalize their site appearance
 * and layout in a user-friendly interface.
 *
 * @package Yaatra
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function yaatra_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' => 'yaatra_customize_partial_blogname',
		) );
		$wp_customize->selective_refresh->add_partial( 'blogdescription', array(
			'selector'        => '.site-description',
			'render_callback' => 'yaatra_customize_partial_blogdescription',
		) );
	}

	require get_template_directory(). '/inc/customizer/cv-override-defaults.php';
	require get_template_directory(). '/inc/customizer/custom-controls/cv-register-custom-controls.php';
    
	/**
     * Register theme upsell sections.
     *
     * @since 1.0.0
     */
    $wp_customize->add_section( new Yaatra_Upsell_Section(
        $wp_customize, 'yaatra_theme_upsell',
            array(
                //'title'    		=> esc_html__( 'Buy Pro', 'yaatra' ),
                'button_text' 	=> esc_html__( 'Explore More Premium Features', 'yaatra' ),
                'button_url'  	=> 'https://codevibrant.com/pricing/?product_id=14399',
                'priority'  	=> 1,
            )
        )
    );

}
add_action( 'customize_register', 'yaatra_customize_register' );

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

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

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

/*--------------------------------------------------------------------------------*/
/**
 * Enqueue required scripts/styles for customizer panel
 *
 * @since 1.0.0
 */
function yaatra_customize_backend_scripts() {
 	
    global $yaatra_theme_version;

    wp_enqueue_style( 'cv-font-awesome', get_template_directory_uri() . '/assets/library/font-awesome/css/all.min.css', array(), '6.5.1' );

     wp_enqueue_style( 'cv-extend-customizer', get_template_directory_uri() . '/inc/customizer/assets/css/extend-customizer.css', array(), esc_attr( $yaatra_theme_version ) );

    wp_enqueue_style( 'cv-custom-control-styles', get_template_directory_uri() . '/inc/customizer/assets/css/cv-custom-control-styles.css', array(), esc_attr( $yaatra_theme_version ) );

    wp_enqueue_script( 'cv-extend-customizer', get_template_directory_uri(). '/inc/customizer/assets/js/extend-customizer.js', array('jquery'), esc_attr( $yaatra_theme_version ), true );

    wp_enqueue_script( 'yaatra_admin_bootstrap', get_template_directory_uri() . '/assets/js/cv-bootstrap-toogle.js', array( 'jquery' ), esc_attr( $yaatra_theme_version ), true );
    
    wp_enqueue_script( 'cv-custom-control-scripts', get_template_directory_uri() . '/inc/customizer/assets/js/cv-custom-control-scripts.js', array( 'jquery', 'customize-controls', 'customize-base' ), esc_attr( $yaatra_theme_version ), true );
}
add_action( 'customize_controls_enqueue_scripts', 'yaatra_customize_backend_scripts', 10 );

/**
 * Load customizer required panels.
 */
require get_template_directory() . '/inc/customizer/extend-customizer/class-customize-panel.php';
require get_template_directory() . '/inc/customizer/extend-customizer/class-customize-section.php';

require get_template_directory() . '/inc/customizer/cv-register-panels-sections.php';
require get_template_directory() . '/inc/customizer/cv-customizer-helper.php';
require get_template_directory() . '/inc/customizer/cv-customizer-callback.php';
require get_template_directory() . '/inc/customizer/cv-customizer-sanitize.php';
require get_template_directory() . '/inc/customizer/cv-customizer-starter.php';

$yaatra_sections_array = array(
	'general'		=> array( 'site-style', 'social-icon', 'colors', 'preloader', 'sidebar', ),
	'header'		=> array( 'site-identity' ),
	'frontpage'		=> array( 'banner' ),
	'innerpage'		=> array( 'archive', 'posts' ),
	'footer'		=> array( 'footer' )
);

foreach ( $yaatra_sections_array as $key => $value ) {
	foreach ( $value as $k => $v ) {
		require get_template_directory() . '/inc/customizer/sections/'. $key . '/' . $v .'.php';
	}
}
