<?php
/**
 * Add SplendorStudio assets.
 *
 * @package SplendorStudio\Framework\Assets
 *
 * @since   1.0.0
 */
class Fancify_Lite_Assets extends Fancify_Lite_Controller {

	/**
	 * Constructor
	 *
	 * @since    1.0.0
	 */
	protected function __construct() {
		$this->register_hook_callbacks();
	}

	/**
	 * Register callbacks for actions and filters
	 *
	 * @since    1.0.0
	 */
	protected function register_hook_callbacks() {
		Fancify_Lite_Actions::add_smart_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
		Fancify_Lite_Actions::add_smart_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
		Fancify_Lite_Actions::add_smart_action( 'after_setup_theme', array( $this, 'add_editor_assets' ) );
	}

	/**
	 * Enqueue script assets.
	 *
	 * @since 1.0.0
	 *
	 * @return void
	 */
	public function enqueue_scripts() {
		// Menu scripts
		wp_enqueue_script(
			'fancifyjs-menu',
			FANCIFY_ASSETS_URL . 'plugins/fancify-menu/js/fancify-menu' . FANCIFY_MIN_JS . '.js',
			array('jquery'),
			FANCIFY_VERSION, 
			true
		);

		wp_enqueue_script(
			'fancifyjs-swiper',
			FANCIFY_ASSETS_URL . 'plugins/swiper/js/swiper' . FANCIFY_MIN_JS . '.js',
			array('jquery'),
			FANCIFY_VERSION,
			true
		);

		wp_enqueue_script(
			'fancifyjs-nanobar', 
			FANCIFY_ASSETS_URL . 'plugins/nanobar/nanobar.min.js', 
			array('jquery'), 
			FANCIFY_VERSION, 
			true 
		);

		wp_enqueue_script(
			'fancifyjs-scrollto', 
			FANCIFY_ASSETS_URL . 'plugins/jquery-scrollto/jquery.scrollTo.min.js', 
			array('jquery'), 
			FANCIFY_VERSION, 
			true
		);

		wp_enqueue_script(
			'fancifyjs-lozad', 
			FANCIFY_ASSETS_URL . 'plugins/lozad/lozad.min.js', 
			array('jquery'), 
			FANCIFY_VERSION, 
			true 
		);

		wp_enqueue_script( 
			'fancifyjs-fancify', 
			FANCIFY_ASSETS_URL . 'js/fancify' . FANCIFY_MIN_JS . '.js',
			array('jquery'),
			FANCIFY_VERSION,
			false
		);

		wp_localize_script( 
			'fancifyjs-fancify',
			'fancifyObject',
			array(
				'preloader_color'   =>   get_theme_mod( 'general_preloading_settings_progressbar_color' , '#000')
			) 
		);

		wp_enqueue_script(
			'fancifyjs-footer',
			FANCIFY_ASSETS_URL . 'js/footer'. FANCIFY_MIN_JS . '.js',
			array('jquery'),
			FANCIFY_VERSION,
			true
		);

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

	/**
	 * Enqueue style assets.
	 *
	 * @since 1.0.9
	 *
	 * @return void
	 */
	public function enqueue_styles() {
		$font_query_args = array(
			'family' => 'Poppins:100,200,300,400,500,600,700,800,900%7CRufina%7CCatamaran:700%7CQuicksand:100,200,300,400,500,600,700,800,900%7CRubik:400',
			'subset' => 'latin'
		);

		wp_enqueue_style(
			'fancify-google-fonts',
			add_query_arg( $font_query_args, "//fonts.googleapis.com/css" ),
			array(),
			null
		);

		//add fontastic font icon collections
		wp_enqueue_style(
			'fancify-font-fontastic',
			FANCIFY_ASSETS_URL . 'css/fancify-font-fontastic' . FANCIFY_MIN_CSS . '.css'
		);

		// add fancify-bootstrap
		wp_enqueue_style(
			'fancify-grid',
			FANCIFY_ASSETS_URL . 'css/fancify-grid.min.css'
		);

		// add menu
		wp_enqueue_style(
			'fancify-menu',
			FANCIFY_ASSETS_URL . 'plugins/fancify-menu/css/fancify-menu' . '.css'
		);

		wp_enqueue_style(
			'fancify-megamenu',
			FANCIFY_ASSETS_URL . 'plugins/fancify-menu/css/fancify-megamenu' . '.css'
		);

		// add custom css
		wp_enqueue_style(
			'fancify-swiper',
			FANCIFY_ASSETS_URL . 'plugins/swiper/css/swiper' . FANCIFY_MIN_CSS . '.css'
		);

		// add custom css
		wp_enqueue_style(
			'fancify-custom',
			FANCIFY_ASSETS_URL . 'css/custom' . FANCIFY_MIN_CSS . '.css'
		);
	}

	/**
	 * Add fancify editor assets.
	 *
	 * @since 1.0.9
	 *
	 * @return void
	 */
	public function add_editor_assets() {
		add_editor_style( 
			FANCIFY_ASSETS_URL . 'css/editor' . FANCIFY_MIN_CSS . '.css' 
		);
	}

}

Fancify_Lite_Assets::get_instance();
