<?php
/**
 * Masterpiece enqueue scripts
 *
 * @package masterpiece
 */

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

if ( ! function_exists( 'masterpiece_scripts' ) ) {
	/**
	 * Load theme's JavaScript and CSS sources.
	 */
	function masterpiece_scripts() {
		// Get the theme data.
		$the_theme = wp_get_theme();
		$theme_version = $the_theme->get( 'Version' );
		
		$css_version = $theme_version . '.' . filemtime(get_template_directory() . '/css/theme.min.css');
		wp_enqueue_style('masterpiece-google-font', 'https://fonts.googleapis.com/css?family=Lato|Roboto|Source+Sans+Pro');
		wp_enqueue_style( 'masterpiece-styles', get_stylesheet_directory_uri() . '/css/theme.min.css', array(), $css_version );

		wp_enqueue_script( 'jquery');
		
		$js_version = $theme_version . '.' . time();
		wp_enqueue_script( 'masterpiece-scripts-bootstrap', get_template_directory_uri() . '/js/bootstrap4/bootstrap.bundle.js', array(), $js_version, true );
		wp_enqueue_script( 'masterpiece-scripts-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), $js_version, true );
		
		if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
			wp_enqueue_script( 'comment-reply' );
		}

		// Easing library
		wp_enqueue_script( 'masterpiece-scripts-easing', get_template_directory_uri() . '/vendor/easing/jquery.easing.js', array('jquery'), $js_version, true );

		wp_enqueue_script( 'masterpiece-script-custom', get_template_directory_uri() . '/js/masterpiece.js', array('jquery'), $js_version, true );
	}
} // endif function_exists( 'masterpiece_scripts' ).

add_action( 'wp_enqueue_scripts', 'masterpiece_scripts' );