<?php 

if ( ! defined( 'ABSPATH' ) ) { exit; }

function hotelgalaxy_current_template_name(){

	global $template;		

	$template_name = basename( str_replace(".php","", $template ) );

	return ('template-homepage' ==  $template_name) ? 'home-default' : basename( $template_name );
}

// 
function hotelgalaxy_get_option( $key ) {

	global $hotelgalaxy_settings;

	$defaults = hotelgalaxy_get_default();

	if ( ! isset( $defaults[ $key ] ) ) {
		return;
	}

	if ( isset( $_REQUEST['wp_customize'] ) ) {

		$hotelgalaxy_settings = wp_parse_args( get_option( 'hotel_galaxy_option', array() ), $defaults );

	}else{

		$hotelgalaxy_settings = wp_parse_args( $hotelgalaxy_settings, $defaults );
	}	

	return $hotelgalaxy_settings[ $key ];
}

// get all settings
function hotelgalaxy_option( $default = null, $key=null ) {

	global $hotelgalaxy_settings;	

	if( $default === null){

		$default = hotelgalaxy_get_default();
	}

	if( $key=== null ){

		$key = 'hotel_galaxy_option';
	}

	if ( isset( $_REQUEST['wp_customize'] ) ) {

		$hotelgalaxy_settings = wp_parse_args( get_option( $key, array() ), $default );

	}else{

		$hotelgalaxy_settings = wp_parse_args( $hotelgalaxy_settings, $default );
	}

	return $hotelgalaxy_settings;
}

// 
add_filter('wp_title', 'hotelgalaxy_custom_wp_title');

function hotelgalaxy_custom_wp_title( $title ) {

	if (is_date()){
		$title = esc_html('Date&nbsp;&#8282;&nbsp;', 'hotel-galaxy');
		$title.= esc_html( get_the_date() );
	}
	
	return $title;
}

function hotelgalaxy_home_section_header( $key, $status = true ){	

	if(!$status){
		return false;
	}

	$hotelgalaxy_settings = hotelgalaxy_option();

	$is_header = $hotelgalaxy_settings['is_home_'.$key.'_header'];
	$is_sub_header = $hotelgalaxy_settings['is_home_'.$key.'_sub_header'];
	$is_seprator = $hotelgalaxy_settings['is_'.$key.'_seprator'];
	$header = $hotelgalaxy_settings['home_'.$key.'_section_header'];
	$sub_header = $hotelgalaxy_settings['home_'.$key.'_section_sub_header'];

	if( $is_header || $is_sub_header || $is_seprator ){


		echo '<div class="entry-header section-header slideInUp">';

		if( $is_header){

			$html_header = sprintf( '<h2 clas="header">%s</h2>',  wpautop($header) );
			echo wp_kses_post( $html_header );			
		}

		if( $is_seprator){
			echo '<div class="bar"></div>';
		}

		if( $is_sub_header ){

			$html_sub_header = sprintf( '<p class="sub-header">%s</p>',  wpautop($sub_header) );
			echo wp_kses_post( $html_sub_header );		

		}
		echo '</div>';
	}
}


// 
function hotelgalaxy_media_query( $device ) {

	$mobile = apply_filters( 'hotelgalaxy_mobile_media_query', '(max-width:768px)' );

	$mobile_menu = apply_filters( 'hotelgalaxy_mobile_menu_media_query', $mobile );
	

	$tablet = apply_filters( 'hotelgalaxy_tablet_media_query', '(min-width: 769px) and (max-width: 1024px)' );

	$desktop = apply_filters( 'hotelgalaxy_desktop_media_query', '(min-width:1025px)' );	

	$query = apply_filters( 'hotelgalaxy_media_queries', array(
		'mobile' 		=> $mobile,
		'mobile-menu' 	=> $mobile_menu,
		'tablet' 		=> $tablet,
		'desktop' 		=> $desktop,	
		
		
	) );

	return $query[ $device ];
}

if ( ! function_exists( 'hotelgalaxy_pro_url' ) ) {
	
	function hotelgalaxy_pro_url( $url = 'https://webdzier.com', $trailingslashit = true ) {

		if ( $trailingslashit ) {
			$url = trailingslashit( $url );
		}		

		return esc_url( $url );
	}
}

add_action( 'customize_controls_enqueue_scripts', 'hotelgalaxy_custom_color_palettes' );

/**
 * Adds custom color palettes to wp.color picker.
 */
function hotelgalaxy_custom_color_palettes() {
	$color_palettes = json_encode(
		array(
			'#000000',
			'#ffffff',
			'#a29060',
			'#fea116',
			'#067eff',
			'#a0d049',
			'#fe4c1c'
		)
	);
	wp_add_inline_script( 'wp-color-picker', 'jQuery.wp.wpColorPicker.prototype.options.palettes = ' . $color_palettes . ';' );
}


if ( ! function_exists( 'hotelgalaxy_menu_search_icon' ) ) {

	add_filter( 'wp_nav_menu_items', 'hotelgalaxy_menu_search_icon', 10, 2 );
	
	function hotelgalaxy_menu_search_icon( $nav, $args ) {		

		if ( hotelgalaxy_get_option('is_menubar_search_icon') == false ) {
			return $nav;
		}
		
		if ( isset( $args->theme_location ) && 'primary' === $args->theme_location ) {
			return sprintf('%1$s<li class="search-item"><a href="javascript:void(0)" class="header_search_btn"  data-toggle="collapse" data-target="#header_search" aria-label="%2$s"><i class="fa fa-search" aria-hidden="true"></i></a> </li>',
				$nav,
				esc_attr__( 'Search Bar', 'hotel-galaxy' )			
			);
		}

		return $nav;
	}
}

if ( ! function_exists( 'hotelgalaxy_navigation_search' ) ) {

	add_action( 'hotelgalaxy_inside_navigation_search', 'hotelgalaxy_navigation_search' );
	
	function hotelgalaxy_navigation_search() {
		
		if ( hotelgalaxy_get_option('is_menubar_search_icon') == false ) {
			return;
		}

		echo apply_filters( 'hotelgalaxy_navigation_search_output', sprintf('<div id="header_search" class="collapse header_search_box"> <span class="search_overlay" data-toggle="collapse" data-target="#header_search"> </span>   <form method="get" class="search-form hg-navigation-search" action="%1$s"> <input type="search" class="search-field" value="%2$s" name="s" title="%3$s"/> <button type="submit" class="search_box-search_btn" aria-label="%2$s"><i class="fa fa-search" aria-hidden="true"></i></a> </form> </div>',
			esc_url( home_url( '/' ) ),
			esc_attr( get_search_query() ),
			esc_attr_x( 'Search', 'label', 'hotel-galaxy' )
		));
	}
}

?>