<?php
/**
 * The header for our theme
 *
 * This is the template that displays all of the <head> section and everything up until <div id="content">
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package Home Gadget 
 */
?>

<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>

<meta http-equiv="Content-Type" content="<?php echo esc_attr(get_bloginfo('html_type')); ?>; charset=<?php echo esc_attr(get_bloginfo('charset')); ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.2, user-scalable=yes" />

<?php wp_head(); ?>

</head>

<body <?php body_class(); ?>>

<?php
	if ( function_exists( 'wp_body_open' ) )
	{
		wp_body_open();
	}else{
		do_action('wp_body_open');
	}
?>
<?php 
if( get_theme_mod('home_gadget_preloader_hide', false ) == true ){ 

	$home_gadget_type = get_theme_mod('home_gadget_preloader_type','diamond');
?>
<div class="frame">
	<div class="loader preloader-types">

		<?php if($home_gadget_type == 'diamond'){ ?>

			<div class="preloader">
				<div class="diamond">
					<span></span>
					<span></span>
					<span></span>
				</div>
			</div>

		<?php } elseif($home_gadget_type == 'orbit'){ ?>

			<div class="orbit-loader">
				<div class="orbit-center"></div>
				<div class="orbit-ring">
					<span></span>
					<span></span>
					<span></span>
				</div>
			</div>

		<?php } elseif($home_gadget_type == 'liquid'){ ?>

			<div class="liquid-loader">
				<div class="liquid-blob"></div>
			</div>

		<?php } ?>

	</div>
</div>
<?php } ?>

<a class="skip-link screen-reader-text" href="#content"><?php esc_html_e( 'Skip to content', 'home-gadget' ); ?></a>

<header id="site-navigation">
	<div class="top-header py-2">
		<div class="container">
			<div class="row">
				<div class="col-lg-3 col-md-3 col-sm-12 align-self-center phone-number">
					<?php if ( get_theme_mod('home_gadget_header_phone_number')) : ?>
						<a href="tel:<?php echo esc_attr( get_theme_mod('home_gadget_header_phone_number' ) ); ?>"><i class="fa-solid fa-phone me-2"></i><span class="phone-no"><?php echo esc_html( get_theme_mod('home_gadget_header_phone_number' ) ); ?></span></a>
					<?php endif; ?>
				</div>
				<div class="col-lg-6 col-md-6 col-sm-12 align-self-center text-center adv-text">
					<?php if ( get_theme_mod('home_gadget_header_advertisement_text') ) : ?>
						<p class="mb-0"></i><?php echo esc_html( get_theme_mod('home_gadget_header_advertisement_text' ) ); ?></p>
					<?php endif; ?>
				</div>
				<div class="col-lg-3 col-md-3 col-sm-12 align-self-center text-end location-text">
					<?php if ( get_theme_mod('home_gadget_location_text')) : ?>
						<a href="<?php echo esc_url( get_theme_mod('home_gadget_location_link' ) ); ?>" class="mb-0"><i class="fas fa-map-marker-alt me-2"></i><?php echo esc_html( get_theme_mod('home_gadget_location_text' ) ); ?></a>
					<?php endif; ?>
				</div>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="middle-header py-2">
			<div class="row">
				<div class="col-xl-3 col-lg-2 col-md-4 col-sm-5 col-12 align-self-center text-center">
					<div class="logo text-lg-start text-md-start text-center mb-3 mb-md-0">
						<div class="logo-image">
							<?php the_custom_logo(); ?>
						</div>
						<div class="logo-content">
							<?php
								if ( get_theme_mod('home_gadget_display_header_title', true) == true ) :
									echo '<a href="' . esc_url(home_url('/')) . '" title="' . esc_attr(get_bloginfo('name')) . '">';
									echo esc_attr(get_bloginfo('name'));
									echo '</a>';
								endif;
								if ( get_theme_mod('home_gadget_display_header_text', false) == true ) :
									echo '<span>'. esc_attr(get_bloginfo('description')) . '</span>';
								endif;
							?>
						</div>
					</div>
				</div>
				<div class="col-xl-5 col-lg-4 col-md-8 col-sm-7 col-12 align-self-center">
					<?php if ( class_exists( 'woocommerce' ) ) { ?>
					<div class="combined-box">
						<div class="category-select">
							<button class="product-btn">
								<i class="fa-solid fa-bars"></i>
								<?php esc_html_e( 'Top best category', 'home-gadget' ); ?>
							</button>
							<div class="product-cat">
								<?php
								$home_gadget_args = array(
									'orderby'    => 'title',
									'order'      => 'ASC',
									'hide_empty' => 0,
									'parent'     => 0
								);

								$home_gadget_product_categories = get_terms( 'product_cat', $home_gadget_args );
								$home_gadget_count = count( $home_gadget_product_categories );

								if ( $home_gadget_count > 0 ) {
									foreach ( $home_gadget_product_categories as $home_gadget_product_category ) {
										$home_gadget_product_cat_id = $home_gadget_product_category->term_id;
										$home_gadget_cat_link       = get_term_link( $home_gadget_product_cat_id );

										if ( $home_gadget_product_category->category_parent == 0 ) { ?>
											<li class="drp_category">
												<a href="<?php echo esc_url( $home_gadget_cat_link ); ?>">
													<?php echo esc_html( $home_gadget_product_category->name ); ?>
												</a>
												<i class="fas fa-chevron-right"></i>
											</li>
										<?php }
									}
								}
								?>
							</div>
						</div>
						<div class="divider"></div>
						<?php if ( get_theme_mod( 'home_gadget_disable_search_icon', 'on' ) ) { ?>
							<div class="search-box">
								<?php if ( class_exists( 'woocommerce' ) ) {
									get_product_search_form();
								} ?>
							</div>
						<?php } ?>
					</div>
					<?php } ?>
				</div>
				<div class="col-xl-4 col-lg-5 col-md-12 col-sm-12 align-self-center py-lg-0 py-md-3">
					<div class="row">
						<div class="col-xl-6 col-lg-7 col-md-6 col-sm-6 col-12 align-self-center text-sm-start text-center">
							<?php if ( get_theme_mod('home_gadget_header_button_url') || get_theme_mod('home_gadget_header_button_text') ) : ?>
								<div class="handyman-btn">
								<a href="<?php echo esc_url( get_theme_mod('home_gadget_header_button_url' ) ); ?>"><i class="fa-solid fa-user me-2"></i><?php echo esc_html( get_theme_mod('home_gadget_header_button_text' ) ); ?></a>
								</div>
							<?php endif; ?>
						</div>
						<div class="col-xl-6 col-lg-5 col-md-6 col-sm-6 col-12 align-self-center text-sm-end text-center">
							<?php if ( get_theme_mod('home_gadget_phone_number') || get_theme_mod('home_gadget_phone_number_text') ) : ?>
								<div class="row header-icon">
									<div class="col-lg-2 col-md-2 col-sm-3 col-5 align-self-center p-0 text-end">
										<i class="fa-solid fa-headset"></i>
									</div>
									<div class="col-lg-10 col-md-10 col-sm-9 col-7 align-self-center text-start">
										<h6 class="mb-0"><?php echo esc_html( get_theme_mod('home_gadget_phone_number_text' ) ); ?></h6>
										<a href="tel:<?php echo esc_attr( get_theme_mod('home_gadget_phone_number' ) ); ?>"><p class="mb-0"><?php echo esc_html( get_theme_mod('home_gadget_phone_number' ) ); ?></p></a>
									</div>
								</div>
							<?php endif; ?>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="bottom-header pt-1 <?php if( get_theme_mod( 'home_gadget_sticky_header',false ) != '') { ?>sticky-header<?php } else { ?>close-sticky <?php } ?>">
		<div class="container">
			<div class="row">
				<div class="col-lg-7 col-md-12 col-sm-3 col-7  order-1  align-self-center text-start">
					<button class="menu-toggle my-2 py-2 px-3" aria-controls="top-menu" aria-expanded="false" type="button">
						<span aria-hidden="true"><i class="fa-solid fa-bars"></i></span>
					</button>
					<nav id="main-menu" class="close-panal">
						<?php
							wp_nav_menu( array(
								'theme_location' => 'main-menu',
								'container' => false
							));
						?>
						<button class="close-menu my-2 p-2" type="button">
							<span aria-hidden="true"><i class="fa fa-times"></i></span>
						</button>
					</nav>
				</div>
				<div class="col-lg-3 col-md-6 col-sm-12 col-12 order-3 align-self-center d-flex justify-content-start column-gap-4 align-items-center">
					<?php if ( get_theme_mod('home_gadget_currency_switcher', 'off' ) == 'on' ) : ?>
						<?php if(class_exists('woocommerce')){ ?>
							<div class="currency-box ">
								<?php echo do_shortcode('[woocommerce_currency_switcher_drop_down_box]'); ?>
							</div>
						<?php } ?>
					<?php endif; ?>
					<?php if ( get_theme_mod('home_gadget_gtranslate', 'on' ) == 'on' ) : ?>
								<?php if(class_exists('GTranslate')){ ?>
									<div class="translate-lang ">
										<?php echo do_shortcode( '[gtranslate]' );?>
									</div>
								<?php } ?>
					<?php endif; ?>
				</div>
				<div class="col-lg-2 col-md-6 col-sm-5 col-5  order-2 order-sm-2 order-md-3 align-self-center text-center d-flex justify-content-between">
					<div class="my-cart">
						<?php if ( class_exists( 'woocommerce' ) ) {?>
							<a class="cart-customlocation" href="<?php if(function_exists('wc_get_cart_url')){ echo esc_url(wc_get_cart_url()); } ?>" title="<?php esc_attr_e( 'View Shopping Cart','home-gadget' ); ?>"><i class="fa-solid fa-bag-shopping me-1"></i><span class="cart-item-box"><?php echo esc_html(wp_kses_data( WC()->cart->get_cart_contents_count() ));?></span></a>
						<?php }?>
					</div>
					<div class="wishlist-icon">
						<?php if(class_exists('woocommerce')){ ?>
							<?php if(defined('YITH_WCWL')){ ?>
								<a class="wishlist_view" href="<?php echo YITH_WCWL()->get_wishlist_url(); ?>" title="<?php esc_attr_e('Wishlist','home-gadget'); ?>"><i class="fa-solid fa-heart"></i></a>
							<?php }?>
						<?php }?>
					</div>
					<div class="my-account">
						<?php if(class_exists('woocommerce')){ ?>
							<?php if ( is_user_logged_in() ) { ?>
								<a href="<?php echo esc_url( get_permalink( get_option('woocommerce_myaccount_page_id') ) ); ?>" title="<?php esc_attr_e('My Account','home-gadget'); ?>"><i class="fa-solid fa-user me-1"></i></i><span class="screen-reader-text"><?php esc_html_e( 'My Account','home-gadget' );?></span></a>
							<?php }
							else { ?>
								<a href="<?php echo esc_url( get_permalink( get_option('woocommerce_myaccount_page_id') ) ); ?>" title="<?php esc_attr_e('Login / Register','home-gadget'); ?>"><i class="fa-solid fa-user me-1"></i></i><span class="screen-reader-text"><?php esc_html_e( 'Login / Register','home-gadget' );?></span></a>
							<?php } ?>
						<?php }?>
					</div>
				</div>
			</div>
		</div>
	</div>
</header>