<?php 
/**
 * Differents hooks for the file
 * @since 1.0
 * @package RoyalNews
 */

# hook for script & style enqueue
add_action( 'wp_enqueue_scripts', 'royalnews_enqueue_scripts' );
# hook for customizer 
add_action( 'customize_controls_enqueue_scripts', 'royalnews_customizer_enqueue_scripts' );

/**
 * Header hooks
 */
add_action( 'royalnews-header-content', 'royalnews_header_site_identity' );
add_action( 'royalnews-header-content', 'royalnews_header_primary_menu', 20 );
if( !function_exists( 'royalnews_header_site_identity' ) ){
	/**
	 * Get Header site identity
	 * @since 1.0
	 * @package RoyalNews
	 */
	function royalnews_header_site_identity(){
		get_template_part( 'templates/header/header', 'content' );
	}
}
if( !function_exists( 'royalnews_header_primary_menu' ) ){
	/**
	 * Get Primary menu
	 * @since 1.0
	 * @package RoyalNews
	 */
	function royalnews_header_primary_menu(){
		get_template_part( 'templates/header/header', 'menu' );
	}
}

add_action( 'royalnews_after_footer', 'royalnews_scroll_to_top' );
/**
 * Add Acroll To Top
 * @since 1.0
 * @package RoyalNews
 */
function royalnews_scroll_to_top(){
	if( !royalnews_value( 'enable_stt' ) ){
		return;
	}?>
	 	<div class="royalnews-scroll-to-top">
		 	<a href="#royalnews-head">
		 	  <div class="royalnews-scroll-arrow">
		 	  	<i class="royalnews-scroll-text fas fa-long-arrow-alt-up"></i>
		 	  </div>
		 	</a>
	 	</div>
<?php }

add_action( 'royalnews-after-header', 'royalnews_header_category' );
/**
 * Header Categoty
 * @since 1.0
 * @package RoyalNews
 */
function royalnews_header_category(){
	$enable = royalnews_value( 'enable-header-cat' );
	if( $enable ){
		get_template_part( 'templates/header/header', 'category' );
	}
}

add_action( 'royalnews-after-header', 'royalnews_header_stories', 20 );
/**
 * Header Top Stories
 * @since 1.0
 * @package RoyalNews
 */
function royalnews_header_stories(){
	$enable = royalnews_value( 'enable-haeder-stories' );
	if( $enable ){
		get_template_part( 'templates/header/header', 'stories' );
	}
}

add_action( 'royalnews-after-header', 'royalnews_site_banner', 30 );
/**
 * Upto banner
 * @since 1.0
 * @package RoyalNews
 */
function royalnews_site_banner(){
	if( is_home() || is_front_page() || is_404() ){
		return;
	}

	$disable_banner = royalnews_get_meta( 'disable-banner' );
	if( $disable_banner ){
		return;
	}

	$img_url = '';
	if( has_header_image() ){
		$src = get_header_image();
		$img_url = 'style="background-image: url( '. esc_url( $src ) .' )"';
	}?>
	<div class="royalnews-single-page-header-wrapper">		
		<div class="royalnews-single-page-header-inner" <?php echo $img_url; ?> >
			<div class="container">
				<?php royalnews_breadcrumb(); ?>			
				<div class="royalnews-single-page-header">
					<?php royalnews_banner_title(); ?>
				</div>	
			</div>
		</div>
	</div>
<?php }

add_action( 'royalnews-after-header', 'royalnews_after_header_widget_area', 40 );
/**
 * After Header Widget area
 * @since 1.0
 * @package RoyalNews
 */
function royalnews_after_header_widget_area(){
	if( is_home() || is_front_page() ){		
		if ( is_active_sidebar( 'royalnews_after_header' ) ){?>
			<div class="royalnews-after-header-widget-area">
				<div class="container">
					<?php dynamic_sidebar( 'royalnews_after_header' ); ?>
				</div>
			</div>
		<?php }
	}
}

add_action( 'royalnews-after-header', 'royalnews_main_slider', 50 );
/**
 * Upto slider
 * @since 1.0
 * @package RoyalNews
 */
function royalnews_main_slider(){
	$enable = royalnews_value( 'enable_slider' );
	if( !is_home() || !is_front_page() ){
		return;
	}
	if( $enable ){
		$post_found_slider = royalnews_posts_by_type( 'category', royalnews_value( 'slider_category' ), 3 );
		$post_found = royalnews_posts_by_type( 'category', royalnews_value( 'post_category' ), 4 );
		set_query_var( 'royalnews_slider_data', $post_found_slider );
		set_query_var( 'royalnews_post_category', $post_found );
		get_template_part( 'templates/header/header', 'banner' );
	}
}

add_action( 'royalnews_before_footer', 'royalnews_before_footer_news' );
/**
 * Footer News
 * @since 1.0
 * @package RoyalNews
 */
function royalnews_before_footer_news(){
	if( is_home() || is_front_page() ){
		if( royalnews_value( 'enable-footer-news' ) ){
			$news_found = royalnews_get_posts_by_type( royalnews_value( 'footer-news-type' ), royalnews_value( 'footer-news-category' ), 6 );
			set_query_var( 'royalnews_footer-news', $news_found );
			get_template_part( 'templates/footer/footer', 'news' );
		}
	}
}

add_action( 'royalnews_before_footer', 'royalnews_before_footer_widget_area' );
/**
 * before Footer Widget area
 * @since 1.0
 * @package RoyalNews
 */
function royalnews_before_footer_widget_area(){
	if( is_home() || is_front_page() ){		
		if ( is_active_sidebar( 'royalnews_before_footer' ) ){?>
			<div class="royalnews-before-footer-widget-area">
				<div class="container">
					<?php dynamic_sidebar( 'royalnews_before_footer' ); ?>
				</div>
			</div>
		<?php }
	}
}

add_action( 'wp_footer', 'royalnews_add_preloader' );
/**
 * Add preloader on site
 * @since 1.0
 * @package RoyalNews
 */
function royalnews_add_preloader(){
	if( royalnews_value( 'enable_preloader' ) ){
		echo '<div class="royalnews-loader-wrapper">';
			echo '<div class="royalnews-loader"></div>';
		echo '</div>';
	}
}