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

// Load customize default values.
require get_template_directory().'/inc/ansar/customize/customizer-callback.php';

// Load customize default values.
require get_template_directory().'/inc/ansar/customize/customizer-default.php';

// Load customize selective Refresh.
require get_template_directory().'/inc/ansar/customize/selective-refresh-and-partial.php';


$repeater_path = trailingslashit( get_template_directory() ) . '/inc/ansar/customizer-repeater/functions.php';
if ( file_exists( $repeater_path ) ) {
    require_once( $repeater_path );
}

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

	// Load customize controls.
	require get_template_directory().'/inc/ansar/customize/customizer-control.php';

    // Load customize sanitize.
	require get_template_directory().'/inc/ansar/customize/customizer-sanitize.php';
    
    $default = newsxo_get_default_theme_options();

	/*theme option panel info*/
    require get_template_directory().'/inc/ansar/customize/site-identity.php';
    
    /*theme Builder option panel info*/
	require get_template_directory() . '/inc/ansar/customize/builder/builder-int.php';

	require get_template_directory().'/inc/ansar/customize/theme-options.php';

    /*Theme customizer general option*/
    require get_template_directory().'/inc/ansar/customize/footer-options.php';

	/*theme general layout panel*/
	require get_template_directory().'/inc/ansar/customize/theme-layout.php';

    /*theme Forntpage Options panel*/
    require get_template_directory() . '/inc/ansar/customize/frontpage-options.php';
    
    //Customizer Core Panel
	require get_template_directory().'/inc/ansar/customize/customize-core.php';
}
add_action('customize_register', 'newsxo_customize_register');


/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function newsxo_customize_preview_js() {
    wp_enqueue_media();
    
    // Enqueue the customizer preview style
    wp_enqueue_style('newsxo-customizer-preview', get_template_directory_uri() . '/assets/css/customizer-preview.css', [], '1.0');

	wp_enqueue_script('newsxo-customizer', get_template_directory_uri().'/assets/js/customizer.js', array('customize-preview'), '20151215', true);
}
add_action('customize_preview_init', 'newsxo_customize_preview_js');

/************************* Theme Customizer with Sanitize function *********************************/
function newsxo_theme_option( $wp_customize ){   
    $newsxo_default = newsxo_get_default_theme_options();

    function newsxo_sanitize_text( $input ) {
        return wp_kses_post( force_balance_tags( $input ) );
    }
}
add_action('customize_register','newsxo_theme_option');

if ( ! function_exists( 'newsxo_get_social_icon_default' ) ) {

    function newsxo_get_social_icon_default() {
        return apply_filters(
            'newsxo_get_social_icon_default',
            json_encode(
                array(
                    array(
                        'icon_value' => 'fab fa-facebook',
                        'link'       => '#',
                        'id'         => 'customizer_repeater_header_social_001',
                    ),
                    array(
                        'icon_value' => 'fa-brands fa-x-twitter',
                        'link'       => '#',
                        'id'         => 'customizer_repeater_header_social_003',
                    ),
                    array(
                        'icon_value' => 'fab fa-instagram',
                        'link'       => '#',
                        'id'         => 'customizer_repeater_header_social_005',
                    ),
                    array(
                        'icon_value' => 'fab fa-youtube',
                        'link'       => '#',
                        'id'         => 'customizer_repeater_header_social_006',
                    ),
                    array(
                        'icon_value' => 'fab fa-telegram',
                        'link'       => '#',
                        'id'         => 'customizer_repeater_header_social_008',
                    ),
                )
            )
        );
    }
}
