<?php
/**
 * Headerdata
 *
 * @package WordPress
 * @subpackage Charity
 * @since Charity 1.0
 */


/*-----------------------------------------------------------------------------------*/
/*	Include CSS
/*-----------------------------------------------------------------------------------*/

if ( !function_exists( 'wplook_css_frontend' ) ) {

	/**
	* Include CSS
	*
	* @since 2.1
	*/

	function wplook_css_frontend() {

		// Vendors
		wp_enqueue_style( 'charity-vendors', get_template_directory_uri() . '/assets/styles/vendors.min.css' );

		// Google Fonts
		wp_enqueue_style( 'google-fonts', 'https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900,100italic,300italic,400italic,700italic,900italic');

		// Main stylesheet
		wp_enqueue_style( 'charity-style', get_stylesheet_uri() );

	}

	add_action( 'wp_enqueue_scripts', 'wplook_css_frontend' );
}


/*-----------------------------------------------------------------------------------*/
/*	Include Java Scripts
/*-----------------------------------------------------------------------------------*/

if ( ! function_exists( 'wplook_scripts_include' ) ) {

	function wplook_scripts_include() {

		/*-----------------------------------------------------------
			Vendors
		-----------------------------------------------------------*/
		wp_enqueue_script( 'jquery' );
		wp_enqueue_script( 'foundation', get_template_directory_uri() . '/assets/javascripts/foundation.min.js', '', '', 'footer' );
		wp_enqueue_script( 'OwlCarousel2', get_template_directory_uri() . '/assets/javascripts/owl.carousel.min.js', '', '', 'footer' );
		wp_enqueue_script( 'fresco', get_template_directory_uri() . '/assets/javascripts/fresco.min.js', '', '', 'footer' );
		wp_enqueue_script( 'fullscreener', get_template_directory_uri() . '/assets/javascripts/jquery.fullscreener.min.js', array( 'jquery' ), '', 'footer' );

		if ( is_singular() && comments_open() && ( get_option( 'thread_comments' ) == 1 ) ) {
			wp_enqueue_script( 'comment-reply' );
		}

		if ( (is_single() && get_post_type() == 'post_events') ) {
			wp_enqueue_script( 'jquery.countdown', get_template_directory_uri() . '/assets/javascripts/jquery.countdown.min.js', array( 'jquery' ), '', 'footer' );
		}

		if( (is_single() && get_post_type() == 'post_causes') || (is_page_template('template-donations.php') || is_page_template('template-donations-cc.php') ) ){
			wp_enqueue_script( 'charity-stripe', 'https://js.stripe.com/v2/', 'jquery', '', 'footer' );
		}
		wp_register_script( 'charity-main', get_template_directory_uri().'/assets/javascripts/app.js', array( 'jquery' ), '', 'footer' );

		wp_localize_script( 'charity-main', 'ajax_var', array(
			'url' => admin_url('admin-ajax.php'),
			'nonce' => wp_create_nonce('ajax-nonce')
		) );
		wp_enqueue_script( 'charity-main' );

		/*-----------------------------------------------------------
			Include Google Maps
		-----------------------------------------------------------*/
		$maps_api_key = ot_get_option( 'wpl_maps_api_server_key' );
		$maps_api_key = $maps_api_key ? $maps_api_key : ot_get_option( 'wpl_maps_api_key' );

		if( !empty( $maps_api_key ) ) {
			wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?v=3.exp&key=' . $maps_api_key );
		} else {
			wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?v=3.exp' );
		}

		wp_enqueue_script( 'wplook-google-maps', get_template_directory_uri() . '/assets/javascripts/google-maps.js', array( 'jquery', 'google-maps-api' ), false, true );

	}
	add_action('wp_enqueue_scripts', 'wplook_scripts_include');
}

/*------------------------------------------------------------
 * Enqueue scripts and styles in wp-admin.
 * ============================================================*/

function wplook_admin_scripts($hook) {
	wp_enqueue_style('thickbox');
	wp_enqueue_script('media-upload');
	wp_enqueue_script('thickbox');
	wp_enqueue_style( 'charity-admin-css', get_template_directory_uri() . '/assets/styles/admin.css' );
	if ( 'widgets.php' == $hook ) {
		wp_enqueue_script('upload_media_widget', get_template_directory_uri().'/assets/javascripts/upload-media.js', '', 'widget', 'footer' );
	}
}
add_action('admin_enqueue_scripts', 'wplook_admin_scripts');
