<?php

namespace Greyd\Navigation;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

new Enqueue();
class Enqueue {

	public function __construct() {
		add_action( 'wp_enqueue_scripts', array( $this, 'load_scripts_head' ) );
		add_action( 'wp_footer', array( $this, 'load_scripts_footer' ) );

		add_action( 'load-nav-menus.php', array( $this, 'load_admin_menu_scripts' ) );
	}

	/**
	 * Load scripts and styles in the head
	 */
	public function load_scripts_head() {
		wp_process_style( 'default_style', get_template_directory() . '/inc/navigation/assets/header.css' );
		wp_process_style( 'default_style', get_template_directory() . '/inc/navigation/assets/footer.css' );

		// CSS
		wp_register_style( 'hamburgers', get_template_directory_uri() . '/inc/navigation/assets/hamburgers.css', null, '1.0', 'all' );
		wp_enqueue_style( 'hamburgers' );
	}

	/**
	 * Load scripts and styles in the footer
	 */
	public function load_scripts_footer() {

		global $config;

		wp_register_script( 'navigation_js', get_template_directory_uri() . '/inc/navigation/assets/navigation.js', array( 'jquery' ), $config->theme_version, false );
		wp_enqueue_script( 'navigation_js' );

		wp_register_script( 'submenu_js', get_template_directory_uri() . '/inc/navigation/assets/submenu.js', array( 'jquery' ), $config->theme_version, false );
		wp_enqueue_script( 'submenu_js' );
	}

	public function load_admin_menu_scripts() {
		add_action( 'admin_enqueue_scripts', array( $this, 'load_iconpicker' ), 99 );
	}

	/**
	 * Load icon picker
	 */
	public function load_iconpicker() {

		global $config;
		
		// elegant icons
		wp_register_style( 'elegant-icons', get_template_directory_uri() . '/assets/font/elegant_icons.css', null, '1.0', 'all' );
		wp_enqueue_style( 'elegant-icons' );
		
		// menu js
		wp_enqueue_media();
		wp_register_script( 'admin-menu', get_template_directory_uri() . '/inc/navigation/assets/admin-menu.js', array( 'jquery' ), $config->theme_version, false );
		wp_enqueue_script( 'admin-menu' );

		// Iconpicker
		$iconpicker_uri = get_template_directory_uri() . '/libs/iconpicker';
		wp_register_style( 'iconpicker-main', $iconpicker_uri . '/css/base/jquery.fonticonpicker.min.css', null, '1.0', 'all' );
		wp_enqueue_style( 'iconpicker-main' );
		wp_register_style( 'iconpicker-main-theme', $iconpicker_uri . '/css/base/jquery.fonticonpicker.grey.min.css', null, '1.0', 'all' );
		wp_enqueue_style( 'iconpicker-main-theme' );
		wp_register_script( 'iconpicker', $iconpicker_uri . '/js/jquery.fonticonpicker.min.js', array( 'jquery' ), '1.0', false );
		wp_enqueue_script( 'iconpicker' );
	}
}
