<?php
/**
 * Excel Business Theme Customizer
 *
 * @package Excel_Business
 */

$excel_business_sections = array( 'info', 'header', 'home', 'styling', 'breadcrumb', 'footer' );

foreach( $excel_business_sections as $s ){
    require get_template_directory() . '/inc/customizer/' . $s . '.php';
}

if( ! function_exists( 'excel_business_get_fontawesome' ) ) :
/**
 * Returns Font-awesome array
*/
function excel_business_get_fontawesome(){
    $font_array = array();
    $fonts = include wp_normalize_path( get_template_directory() . '/inc/customizer/fonts.php' );
    foreach( $fonts as $font ){
        $font_array[$font] = $font;
    }
    return $font_array;
}
endif;

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

function excel_business_customize_js() {
	wp_enqueue_script( 'excel_business_customize', get_template_directory_uri() . '/inc/js/customize.js', array( 'jquery' ), EXCEL_BUSINESS_VERSION, true );
}
add_action( 'customize_controls_enqueue_scripts', 'excel_business_customize_js' );

/**
 * Sanitization function for checkbox
*/
function excel_business_sanitize_checkbox( $checked ){
    // Boolean check.
    return ( ( isset( $checked ) && true == $checked ) ? true : false );
}

/**
 * Sanitization function for select
*/
function excel_business_sanitize_select( $input, $setting ) {
	// Ensure input is a slug.
	$input = sanitize_key( $input );
	// Get list of choices from the control associated with the setting.
	$choices = $setting->manager->get_control( $setting->id )->choices;
	// If the input is a valid key, return it; otherwise, return the default.
	return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
}

/**
 * Sanitization function for slider choices 
*/
function excel_business_sanitize_slider( $input, $setting ) {
	// Ensure input is a slug.
	$input = sanitize_text_field( $input );
	// Get list of choices from the control associated with the setting.
	$choices = $setting->manager->get_control( $setting->id )->choices;
	// If the input is a valid key, return it; otherwise, return the default.
	return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
}