<?php
/**
 * The header for our theme
 *
 * @package Storecraft
 * @since 1.0
 */

?><!DOCTYPE html>
<html <?php language_attributes(); ?> class="no-js no-svg">
<head>
	<meta charset="<?php bloginfo( 'charset' ); ?>">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<?php wp_head(); ?>
</head>

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

<?php
if ( function_exists( 'wp_body_open' ) ) {
	wp_body_open();
} else {
	do_action( 'wp_body_open' );
}

$storecraft_cart_count  = 0;
$storecraft_cart_url    = home_url( '/' );
$storecraft_account_url = wp_login_url();

if ( class_exists( 'WooCommerce' ) ) {
	if ( function_exists( 'WC' ) && WC()->cart ) {
		$storecraft_cart_count = WC()->cart->get_cart_contents_count();
		$storecraft_cart_url   = wc_get_cart_url();
	}
	$storecraft_account_page = get_option( 'woocommerce_myaccount_page_id' );
	if ( $storecraft_account_page ) {
		$storecraft_account_url = get_permalink( $storecraft_account_page );
	}
}

$storecraft_currency_text = get_theme_mod( 'storecraft_header_language_text', __( 'USD', 'storecraft' ) );
$storecraft_wishlist_url  = get_theme_mod( 'storecraft_wishlist_url', '' );
$storecraft_topbar_text   = get_theme_mod( 'storecraft_topbar_text', __( 'Free Shipping on Orders Over $59', 'storecraft' ) );
$storecraft_show_topbar   = get_theme_mod( 'storecraft_show_topbar', true );

if ( empty( $storecraft_wishlist_url ) ) {
	$storecraft_wishlist_url = $storecraft_account_url;
}

$storecraft_header_class = storecraft_get_header_modifier_class();
?>

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

<header id="header" class="<?php echo esc_attr( 'hbs-header hbs-luxury-header ' . $storecraft_header_class ); ?>">
	<?php if ( $storecraft_show_topbar && ! empty( $storecraft_topbar_text ) ) : ?>
		<div class="hbs-topbar">
			<div class="container">
				<p class="hbs-topbar-text"><?php echo esc_html( $storecraft_topbar_text ); ?></p>
			</div>
		</div>
	<?php endif; ?>

	<div class="hbs-header-bar">
		<div class="container hbs-header-bar-inner">

			<div class="hbs-header-brand">
				<button type="button" class="hbs-mobile-toggle toggle nav-toggle mobile-nav-toggle" data-toggle-target=".menu-modal" data-toggle-body-class="showing-menu-modal" aria-expanded="false" data-set-focus=".close-nav-toggle" aria-label="<?php esc_attr_e( 'Open menu', 'storecraft' ); ?>">
					<span class="hbs-hamburger" aria-hidden="true">
						<span></span>
						<span></span>
						<span></span>
					</span>
				</button>

				<a class="hbs-logo-link" href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
					<?php if ( has_custom_logo() ) : ?>
						<span class="hbs-logo-image"><?php the_custom_logo(); ?></span>
					<?php endif; ?>
					<?php if ( get_theme_mod( 'storecraft_show_site_title', true ) ) : ?>
						<?php $storecraft_blog_info = get_bloginfo( 'name' ); ?>
						<?php if ( ! empty( $storecraft_blog_info ) ) : ?>
							<?php if ( is_front_page() && is_home() ) : ?>
								<h1 class="hbs-site-name site-title"><?php bloginfo( 'name' ); ?></h1>
							<?php elseif ( is_front_page() ) : ?>
								<h1 class="hbs-site-name site-title"><?php bloginfo( 'name' ); ?></h1>
							<?php else : ?>
								<span class="hbs-site-name site-title"><?php bloginfo( 'name' ); ?></span>
							<?php endif; ?>
						<?php endif; ?>
					<?php endif; ?>
				</a>
			</div>

			<nav id="site-navigation" class="hbs-primary-nav main-navigation" aria-label="<?php esc_attr_e( 'Primary Menu', 'storecraft' ); ?>">
				<?php
				wp_nav_menu(
					array(
						'theme_location' => 'primary',
						'menu_id'        => 'primary-menu',
						'menu_class'     => 'hbs-nav-menu primary-menu',
						'container'      => false,
						'fallback_cb'    => 'wp_page_menu',
						'depth'          => 3,
					)
				);
				?>
			</nav>

			<div class="hbs-header-actions">
				<?php if ( get_theme_mod( 'storecraft_show_currency', true ) ) : ?>
					<span class="hbs-action-item hbs-currency" aria-label="<?php esc_attr_e( 'Currency', 'storecraft' ); ?>">
						<span class="hbs-currency-label"><?php echo esc_html( $storecraft_currency_text ); ?></span>
					</span>
				<?php endif; ?>

				<?php if ( get_theme_mod( 'storecraft_show_search', true ) ) : ?>
					<div class="hbs-header-search">
						<button type="button" class="hbs-action-item hbs-search-toggle" aria-expanded="false" aria-controls="hbs-header-search-form" aria-label="<?php esc_attr_e( 'Search', 'storecraft' ); ?>">
							<i class="fas fa-search" aria-hidden="true"></i>
						</button>
						<div id="hbs-header-search-form" class="hbs-search-dropdown" hidden>
							<?php get_search_form(); ?>
						</div>
					</div>
				<?php endif; ?>

				<?php if ( get_theme_mod( 'storecraft_show_account', true ) ) : ?>
					<a class="hbs-action-item hbs-account" href="<?php echo esc_url( $storecraft_account_url ); ?>" aria-label="<?php esc_attr_e( 'Account', 'storecraft' ); ?>">
						<i class="far fa-user" aria-hidden="true"></i>
					</a>
				<?php endif; ?>

				<?php if ( get_theme_mod( 'storecraft_show_wishlist', true ) ) : ?>
					<a class="hbs-action-item hbs-wishlist" href="<?php echo esc_url( $storecraft_wishlist_url ); ?>" aria-label="<?php esc_attr_e( 'Wishlist', 'storecraft' ); ?>">
						<i class="far fa-heart" aria-hidden="true"></i>
					</a>
				<?php endif; ?>

				<?php if ( get_theme_mod( 'storecraft_show_cart', true ) ) : ?>
					<a class="hbs-action-item hbs-cart cart-contents" href="<?php echo esc_url( $storecraft_cart_url ); ?>" aria-label="<?php esc_attr_e( 'Cart', 'storecraft' ); ?>">
						<i class="far fa-shopping-bag" aria-hidden="true"></i>
						<span class="hbs-badge count"><?php echo esc_html( $storecraft_cart_count ); ?></span>
					</a>
				<?php endif; ?>
			</div>

		</div>
	</div>

	<?php get_template_part( '/inc/modal-menu' ); ?>
</header>

<?php
$storecraft_show_inner_header = ( is_singular() || is_archive() || is_search() || ( is_home() && ! is_front_page() ) ) && ! is_front_page() && ! ( function_exists( 'is_product' ) && is_product() );
if ( $storecraft_show_inner_header ) :
	$storecraft_inner_title = storecraft_get_inner_page_title();
	?>
	<div id="inner-pages-header" class="hbs-inner-header">
		<div class="header-overlay"></div>
		<div class="header-content">
			<div class="container">
				<h1><?php echo esc_html( $storecraft_inner_title ); ?></h1>
				<div class="innheader-border"></div>
				<div class="theme-breadcrumb mt-2">
					<?php storecraft_breadcrumb(); ?>
				</div>
			</div>
		</div>
	</div>
<?php endif; ?>
