<?php function consultco_scripts() {

	wp_enqueue_style('bootstrap', get_template_directory_uri() . '/css/bootstrap.css');

	wp_enqueue_style( 'consultco-style', get_stylesheet_uri() );
	
	wp_enqueue_style('consultco-default', get_template_directory_uri() . '/css/colors/default.css');
	
	wp_enqueue_style('smartmenus',get_template_directory_uri().'/css/jquery.smartmenus.bootstrap.css');	

	wp_enqueue_style('font-awesome-5-all',get_template_directory_uri().'/css/font-awesome/css/all.min.css');

	wp_enqueue_style('font-awesome-4-shim',get_template_directory_uri().'/css/font-awesome/css/v4-shims.min.css');

	wp_enqueue_style('animate',get_template_directory_uri().'/css/animate.css');

	wp_enqueue_style('bootstrap-progressbar', get_template_directory_uri() . '/css/bootstrap-progressbar.css');

	/* Js script */

	wp_enqueue_script( 'consultco-navigation', get_template_directory_uri() . '/js/navigation.js', array('jquery'));

	wp_enqueue_script('bootstrap', get_template_directory_uri() . '/js/bootstrap.js', array('jquery'));

	wp_enqueue_script('smartmenus-js', get_template_directory_uri() . '/js/jquery.smartmenus.js' , array('jquery'));

	wp_enqueue_script('bootstrap-smartmenus-js', get_template_directory_uri() . '/js/bootstrap-smartmenus.js' , array('jquery'));
	
	wp_enqueue_script('consultco-main-js', get_template_directory_uri() . '/js/main.js' , array('jquery'));

	wp_enqueue_script('consultco-jquery.sticky-js', get_template_directory_uri() . '/js/jquery.sticky.js' , array('jquery'));

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action('wp_enqueue_scripts', 'consultco_scripts');

/**
 	* Added skip link focus
 	*/
	function consultco_skip_link_focus_fix() {
	?>
	<script>
	/(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1);
	</script>
	<?php
	}
add_action( 'wp_print_footer_scripts', 'consultco_skip_link_focus_fix' );

function consultco_customizer_selective_preview() {
	wp_enqueue_script(
		'consultco-customizer-preview', get_template_directory_uri() . '/js/customizer.js', array(
			'jquery',
			'customize-preview',
		), 999, true
	);
}

add_action( 'customize_preview_init', 'consultco_customizer_selective_preview' );


if ( ! function_exists( 'consultco_admin_scripts' ) ) :
function consultco_admin_scripts() {
    wp_enqueue_script( 'consultco-admin-script', get_template_directory_uri() . '/js/consultco-admin-script.js', array( 'jquery' ), '', true );
    wp_localize_script( 'consultco-admin-script', 'consultco_ajax_object',
        array( 'ajax_url' => admin_url( 'admin-ajax.php' ) )
    );
    wp_enqueue_style('consultco-admin-style-css', get_template_directory_uri() . '/css/customizer-controls.css');
}
endif;
add_action( 'admin_enqueue_scripts', 'consultco_admin_scripts' );

function consultco_menu(){ ?>
	<script>
jQuery('a,input').bind('focus', function() {
   if(!jQuery(this).closest(".menu-item").length && ( jQuery(window).width() <= 992) ) {
	    jQuery('.navbar-collapse').removeClass('show');
	}})
</script>
<?php } 
add_action( 'wp_footer', 'consultco_menu' );
	

if ( ! function_exists( 'consultco_header_color' ) ) :

function consultco_header_color() {
    $consultco_logo_text_color = get_header_textcolor();
    $consultco_bg_color = get_background_color();

    ?>
    <style type="text/css">
    <?php
        if ( ! display_header_text() ) :
    ?>
        .site-title,
        .site-description {
            position: absolute;
            clip: rect(1px, 1px, 1px, 1px);
        }
    <?php
        else :
    ?>
        body .site-title a,
        body .site-description {
            color: #<?php echo esc_attr( $consultco_logo_text_color ); ?>;
        }
    <?php endif; ?>
	.wrapper{
		background-color: #<?php echo esc_attr( $consultco_bg_color ); ?>;
	}
    </style>
    <?php
}
endif;



function consultco_archive_page_title(){
	if( is_archive() )
	{
		$consultco_archive_title = get_theme_mod('archive_page_title', esc_html__('Archive','consultco'));
		
		echo '<div class="bs-breadcrumb-title"><h1 class="page-title">';
		
		if ( is_day() ) :
		
		  printf( esc_html__( '%1$s: %2$s', 'consultco' ), esc_html($consultco_archive_title), esc_html(get_the_date()) );
		  
        elseif ( is_month() ) :
		
		  printf( esc_html__( '%1$s: %2$s', 'consultco' ), esc_html($consultco_archive_title), esc_html(get_the_date()) );
		  
        elseif ( is_year() ) :
		
		  printf( esc_html__( '%1$s: %2$s', 'consultco' ), esc_html($consultco_archive_title), esc_html(get_the_date()) );
		  
        elseif( is_category() ):
		
			$consultco_category_title = get_theme_mod('category_page_title',esc_html__('Category','consultco'));
			
			printf( esc_html__( '%1$s: %2$s', 'consultco' ), esc_html($consultco_category_title), single_cat_title( '', false ) );
			
		elseif( is_author() ):
			
			$consultco_author_title = get_theme_mod('author_page_title',esc_html__('All posts by','consultco'));
		
			printf( esc_html__( '%1$s %2$s', 'consultco' ), esc_html($consultco_author_text), esc_html(get_the_author() ));
			
		elseif( is_tag() ):
			
			$agencyyp_tag_title = get_theme_mod('tag_page_title',esc_html__('Tag','consultco'));
			
			printf( esc_html__( '%1$s: %2$s', 'consultco' ), esc_html($agencyyp_tag_title), single_tag_title( '', false ) );
			
		elseif( class_exists( 'WooCommerce' ) && is_shop() ):
			
		$consultco_shop_title = get_theme_mod('shop_page_title',esc_html__('Shop','consultco'));
			
		printf( esc_html__( '%1$s: %2$s', 'consultco' ), esc_html($consultco_shop_title), single_tag_title( '', false ));
			
        elseif( is_archive() ): 
		the_archive_title( '<h1 class="page-title">', '</h1>' ); 
		
		endif;
		

		echo '</h1></div>';
	}
	elseif( is_search() )
	{
		$consultco_search_title = get_theme_mod('search_prefix',__('Search results for','consultco'));
		
		echo '<h1 class="page-title">';
		
		printf( esc_html__( '%1$s: %2$s', 'consultco' ), esc_html($consultco_search_title), get_search_query() );
		
		echo '</h1>';
	}
	elseif( is_404() )
	{
		$consultco_404_title = get_theme_mod('404_page_title',__('404','consultco'));
		
		printf( esc_html__( '%1$s: %2$s', 'consultco' ) , esc_html($consultco_404_title), '' );
		
		echo '</h1>';
	}
	else
	{
		  	$allowed_html = array(
									'br'     => array(),
									'em'     => array(),
									'strong' => array(),
									'i'      => array(
										'class' => array(),
									),
									'span'   => array(),
								);	
		
		echo '<div class="bs-breadcrumb-title"><h1 class="page-title">'.esc_html(get_the_title(), $allowed_html).'</h1></div>';
	}
}


/**
 * Add Cart icon and count to header if WC is active
 */
function consultco_wc_cart_count() {
 
    if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
 
        $count = WC()->cart->cart_contents_count;
        ?>

        <a class="top-cart ms-auto" href="<?php echo WC()->cart->get_cart_url(); ?>"><i class="fas fa-shopping-cart"></i>
        <?php
        if ( $count > 0 ) {
            ?>
            <span class="cart-contents-count"><?php echo esc_html( $count ); ?></span>
            <?php
        }
                ?></a><?php
    }
 
}
add_action( 'consultco_header_top', 'consultco_wc_cart_count' );