<?php

/**
 * edu-light functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package edu-light
 */
/**
 * require edu-light int.
 */
require get_template_directory() . '/inc/init.php';



if ( ! function_exists( 'edu_light_setup' ) ) :
	/**
	 * Sets up theme defaults and registers support for various WordPress features.
	 *
	 * Note that this function is hooked into the after_setup_theme hook, which
	 * runs before the init hook. The init hook is too late for some features, such
	 * as indicating support for post thumbnails.
	 */
	function edu_light_setup() {
		/*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on edu-light, use a find and replace
		 * to change 'edu-light' to the name of your theme in all the template files.
		 */
		load_theme_textdomain( 'edu-light', get_template_directory() . '/languages' );

		// Add default posts and comments RSS feed links to head.
		add_theme_support( 'automatic-feed-links' );

		/*
		 * Let WordPress manage the document title.
		 * By adding theme support, we declare that this theme does not use a
		 * hard-coded <title> tag in the document head, and expect WordPress to
		 * provide it for us.
		 */
		add_theme_support( 'title-tag' );

		/*
		 * Enable support for Post Thumbnails on posts and pages.
		 *
		 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
		 */
		add_theme_support( 'post-thumbnails' );

		// This theme uses wp_nav_menu() in one location.
		register_nav_menus( array(
			'menu-1' => esc_html__( 'Primary', 'edu-light' ),
			'social' => esc_html__( 'Social Menu', 'edu-light' ),
		) );

		/*
		 * Switch default core markup for search form, comment form, and comments
		 * to output valid HTML5.
		 */
		add_theme_support( 'html5', array(
			'search-form',
			'comment-form',
			'comment-list',
			'gallery',
			'caption',
		) );

		// Set up the WordPress core custom background feature.
		add_theme_support( 'custom-background', apply_filters( 'edu_light_custom_background_args', array(
			'default-color' => 'ffffff',
			'default-image' => '',
		) ) );

		//add active class on active nav 
		add_filter('nav_menu_css_class', 'add_active_class', 10, 2 );
		function add_active_class($classes, $item) {
		  if( $item->menu_item_parent == 0 && in_array('current-menu-item', $classes) ) {
		    $classes[] = "active";
		  }

		  return $classes;
		}

		// Add theme support for selective refresh for widgets.
		add_theme_support( 'customize-selective-refresh-widgets' );

		// image size
		// add_image_size( 'edu-light-main-banner',1360, 760, true );
		add_image_size( 'edu-light-about-image',600, 400, true );
		add_image_size( 'edu-light-service-image',600, 400, true );
		add_image_size( 'edu-light-testimonial-thumbnail',150, 150, true );


		/**
		 * Add support for core custom logo.
		 *
		 * @link https://codex.wordpress.org/Theme_Logo
		 */
		add_theme_support( 'custom-logo', array(
			'height'      => 250,
			'width'       => 250,
			'flex-width'  => true,
			'flex-height' => true,
		) );
	}
endif;
add_action( 'after_setup_theme', 'edu_light_setup' );

/*woocommerce support*/
	add_theme_support( 'woocommerce' );

/*breadcrum function*/

if ( ! function_exists( 'edu_light_simple_breadcrumb' ) ) :

	/**
	 * Simple breadcrumb.
	 *
	 * @since 1.0.0
	 */
	function edu_light_simple_breadcrumb() {

		if ( ! function_exists( 'breadcrumb_trail' ) ) {
			require_once get_template_directory() . '/assets/breadcrumbs/breadcrumbs.php';
		}

		$breadcrumb_args = array(
			'container'   => 'div',
			'show_browse' => false,
		);
		breadcrumb_trail( $breadcrumb_args );

	}

endif;

// for font 
function edu_light_google_fonts()
{
	global $edu_light_customizer_all_values;
	$fonts_url = '';
	$fonts     = array();

	$edu_light_font_family_site_identity = $edu_light_customizer_all_values['edu-light-font-family-site-identity'];
	$edu_light_font_family_menu = $edu_light_customizer_all_values['edu-light-font-family-menu'];
	$edu_light_font_family_h1_h6 = $edu_light_customizer_all_values['edu-light-font-family-h1-h6'];

	$edu_light_pro_fonts = array();
	$edu_light_pro_fonts[]=$edu_light_font_family_site_identity;
	$edu_light_pro_fonts[]=$edu_light_font_family_menu;
	$edu_light_pro_fonts[]=$edu_light_font_family_h1_h6;

	 $edu_light_pro_fonts_stylesheet = '//fonts.googleapis.com/css?family=';

	  $i  = 0;
	  for ($i=0; $i < count( $edu_light_pro_fonts ); $i++) { 

	    if ( 'off' !== sprintf( _x( 'on', '%s font: on or off', 'edu-light' ), $edu_light_pro_fonts[$i] ) ) {
			$fonts[] = $edu_light_pro_fonts[$i];
		}

	  }

	if ( $fonts ) {
		$fonts_url = add_query_arg( array(
			'family' => urldecode( implode( '|', $fonts ) ),
		), 'https://fonts.googleapis.com/css' );
	}

	return $fonts_url;

}


/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
function edu_light_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'edu_light_content_width', 640 );
}
add_action( 'after_setup_theme', 'edu_light_content_width', 0 );

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
/**
 * Enqueue scripts and styles.
 */
function edu_light_scripts() {


	wp_enqueue_style( 'edu-light-style', get_stylesheet_uri() );
	//root path for style and scripts
	$assets_url = get_template_directory_uri() .'/assets/';

	// google font
	wp_enqueue_style( 'edu-light-google-fonts', edu_light_google_fonts() );

	//bootstrap
	wp_enqueue_style( 'bootstrap-style', $assets_url . '/vendor/bootstrap/bootstrap.css', array());/*added*/

	//inline style
	wp_add_inline_style( 'edu-light-style', edu_light_inline_style() );
	
	//fontawesome 
	wp_enqueue_style( 'font-awesome', $assets_url .  '/font-awesome/css/font-awesome.css', array(), '4.6.3' );
	//slick
	wp_enqueue_style( 'slick-style', $assets_url . '/vendor/slick/slick.css', array());/*added*/

	wp_enqueue_style( 'slick-theme', $assets_url . '/vendor/slick/slick.theme.css', array());/*added*/

	
	wp_enqueue_script( 'edu-light-navigation', $assets_url . '/js/navigation.js', array(), '20151215', true );
	wp_enqueue_script( 'edu-light-skip-link-focus-fix', $assets_url . '/js/skip-link-focus-fix.js', array(), '20151215', true );

	//third party script enquee
	//bootstrap
	wp_enqueue_script( 'bootstrap', $assets_url . '/vendor/bootstrap/bootstrap.js', array('jquery'), true );
	
	//slick
	wp_enqueue_script( 'slick-script', $assets_url . '/vendor/slick/slick.js', array('jquery'), true );

	
	//jquerysticky
	wp_enqueue_script( 'jquery-sticky', $assets_url . '/vendor/jquery.sticky.js', array('jquery'), true );

	// fonts 
	wp_enqueue_style( 'salient-news-font-awesome', $assets_url . '/vendor/font-awesome/css/font-awesome.css', array());

	
	//parallax
	wp_enqueue_script( 'parallax', $assets_url . '/vendor/parallax.js', array('jquery'), true );

	//nicescroll
	wp_enqueue_script( 'nicescroll', $assets_url . '/vendor/jquery.nicescroll.js', array('jquery'), true );

	//custom script goes here
	wp_enqueue_script( 'edu-light-custom-script', $assets_url . '/js/custom.js', array('jquery'), true );
	
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'edu_light_scripts' );

/**
 * Implement the Custom Header feature.
 */
require get_template_directory() . '/inc/custom-header.php';

/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/template-tags.php';

/*update to pro link*/
require_once( trailingslashit( get_template_directory() ) . 'trt-customize-pro/edu-light/class-customize.php' );


/**
 * Load Jetpack compatibility file.
 */
if ( defined( 'JETPACK__VERSION' ) ) {
	require get_template_directory() . '/inc/jetpack.php';
}

function edu_light_primary_menu_callback() {
	?>
		<ul id="menu">
			<li><a href="<?php echo esc_url( home_url( '/' ) );?>"><?php esc_html_e('Home','edu-light');?></a></li>
			<li><a href="<?php echo esc_url( admin_url( '/nav-menus.php' ) );?>"><?php esc_html_e('Set Primary Menu','edu-light');?></a></li>
		</ul>
	<?php
}

if ( ! function_exists( ' edu_light_social_menu_callback' ) ) :
	/**
	 * Fallback menu to social menu 
	 * 
	 * @since  edu-light 1.0.1
	 */
	function edu_light_social_menu_callback(){
		?>
		<ul id="menu">
			<li><a href="" target="_tab"><?php echo esc_html_e('facebook', 'edu-light' );?></a></li>
			<li><a href="" target="_tab"><?php echo esc_html_e('twitter', 'edu-light' );?></a></li>
		</ul>
		<?php
	}
endif;


if( ! function_exists( 'edu_light_recommended_plugins' ) ) :

  /**
   * Recommended plugins
   *
   * @since  edu_light 1.0.0
   */
  function edu_light_recommended_plugins(){
      $edu_light_plugins = array(
        array(
            'name'     => esc_html__( 'WooCommerce', 'edu-light' ),
            'slug'     => 'WooCommerce',
            'required' => false,
        ),
         
      );
      $edu_light_plugins_config = array(
          'dismiss_msg'     => __( 'Download the plugin for contact section', 'edu-light' ),
          'dismissable' => false,
      );
      
      tgmpa( $edu_light_plugins, $edu_light_plugins_config );
  }
endif;

add_action( 'tgmpa_register', 'edu_light_recommended_plugins' );
