<?php
if( ! function_exists( 'impulsive_custom_styles' ) ) :

function impulsive_custom_styles($custom) {

	// Heading Fonts
	$headings_font = esc_html(get_theme_mod('impulsive_headings_fonts'));

    // Body Fonts
	$body_font = esc_html(get_theme_mod('impulsive_body_fonts'));

	if ( $headings_font ) {

		$font_pieces = explode(":", $headings_font);
		$custom .= "h1, h2, h3, h4, h5, h6, span.site-title { font-family: {$font_pieces[0]}; }"."\n";
	}

	if ( $body_font ) {

		$font_pieces = explode(":", $body_font);
		$custom .= "body, button, input, select, textarea { font-family: {$font_pieces[0]}; }"."\n";
	}

	//Output all the styles
	wp_add_inline_style( 'impulsive-css', $custom );

}
endif;
add_action( 'wp_enqueue_scripts', 'impulsive_custom_styles' );

/*************  
 * 
 * impulsive Theme Customizer with Sanitize function Code Start Here
 *   
**************/

/****
 *  impulsive checkbox sanitize function  
****/
function impulsive_sanitize_checkbox_function( $checked ) {
	// Boolean check.
	return ( ( isset( $checked ) && true == $checked ) ? true : false );
}

/****
 *  impulsive Fonts Sanitize function  
****/
function impulsive_sanitize_fonts( $input ) {
	$valid = array(
			'Source Sans Pro' => 'Source Sans Pro',
			'Open Sans' => 'Open Sans',
			'Oswald' => 'Oswald',
			'Playfair Display' => 'Playfair Display',
			'Montserrat' => 'Montserrat',
			'Raleway' => 'Raleway',
			'Droid Sans' => 'Droid Sans',
			'Lato' => 'Lato',
			'Arvo' => 'Arvo',
			'Lora' => 'Lora',
			'Merriweather' => 'Merriweather',
			'Oxygen' => 'Oxygen',
			'PT Serif' => 'PT Serif',
			'PT Sans' => 'PT Sans',
			'PT Sans Narrow' => 'PT Sans Narrow',
			'Cabin' => 'Cabin',
			'Fjalla One',
			'Francois One',
			'Josefin Sans' => 'Josefin Sans',
			'Libre Baskerville' => 'Libre Baskerville',
			'Arimo' => 'Arimo',
			'Ubuntu' => 'Ubuntu',
			'Bitter' => 'Bitter',
			'Droid Serif' => 'Droid Serif',
			'Roboto' => 'Roboto',
			'Open Sans Condensed' => 'Open Sans Condensed',
			'Roboto Condensed' => 'Roboto Condensed',
			'Roboto Slab' => 'Roboto Slab',
			'Yanone Kaffeesatz' => 'Yanone Kaffeesatz',
			'Rokkitt' => 'Rokkitt',
	);

	if ( array_key_exists( $input, $valid ) ) {
		return $input;
	} else {
		return '';
	}
}
/*************  
 * 
 * impulsive Theme Customizer with Sanitize function Code End Here
 *   
**************/

function impulsive_scripts() {
    $headings_font = esc_html(get_theme_mod('impulsive_headings_fonts'));
    $body_font = esc_html(get_theme_mod('impulsive_body_fonts'));

    if( $headings_font ) {
        wp_enqueue_style( 'impulsive-headings-fonts', '//fonts.googleapis.com/css?family='. $headings_font );
    } else {
        wp_enqueue_style( 'impulsive-source-sans', '//fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic');
    }
    if( $body_font ) {
        wp_enqueue_style( 'impulsive-body-fonts', '//fonts.googleapis.com/css?family='. $body_font );
    } else {
        wp_enqueue_style( 'impulsive-source-body', '//fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,400italic,700,600');
    }
}
add_action( 'wp_enqueue_scripts', 'impulsive_scripts' );