<?php
/**
 * The header for our theme
 *
 * @package Butcher Meatshop
 */
?>
<!doctype html>
<html <?php language_attributes(); ?>>
<head>
    <meta charset="<?php bloginfo( 'charset' ); ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="profile" href="https://gmpg.org/xfn/11">
    <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
<?php wp_body_open(); ?>
<div id="page" class="site">
    <a class="skip-link screen-reader-text" href="#primary"><?php esc_html_e( 'Skip to content', 'butcher-meatshop' ); ?></a>

    <?php
    // Check if preloader is enabled in the theme customizer
    $butcher_meatshop_preloader_wrap = absint( get_theme_mod( 'butcher_meatshop_enable_preloader', 0 ) );
    if ( $butcher_meatshop_preloader_wrap === 1 ) : ?>
        <div id="loader">
            <div class="loader-container">
                <div id="preloader" class="loader-2">
                    <div class="dot"></div>
                </div>
            </div>
        </div>
    <?php endif; ?>

    <header id="masthead" class="site-header">
        <div class="headermain <?php echo esc_attr( get_theme_mod( 'butcher_meatshop_enable_sticky_header', false ) ? 'sticky-header' : '' ); ?>">
            <div class="header-info-box">
                <div class="container">
                    <div class="flex-row">
                        <div class="top-left">
                            <span class="header-search">
                                <span class="search-box text-center">
                                    <button type="button" class="search-open"><i class="fas fa-search"></i></button>
                                </span>
                            </span>
                            <?php if ( get_theme_mod( 'butcher_meatshop_header_info_phone','1234567890' ) ) : ?>
                                <span class="contact-info">
                                    <span class="main-box phone">
                                        <span class="main-head">
                                            <a href="tel:<?php echo esc_attr( get_theme_mod( 'butcher_meatshop_header_info_phone','1234567890' ) ); ?>">
                                                <i class="<?php echo esc_attr(get_theme_mod('fas fa-phone','fas fa-phone')); ?>"></i><span><?php echo esc_html( get_theme_mod( 'butcher_meatshop_header_info_phone','1234567890' ) ); ?></span>
                                            </a>
                                        </span>
                                    </span>
                                </span>
                            <?php endif; ?>
                            <?php if ( get_theme_mod( 'butcher_meatshop_header_info_email','info@example.com' ) ) : ?>
                                <span class="contact-info">
                                    <span class="main-box mail">
                                        <span class="main-head">
                                            <a href="mailto:<?php echo esc_attr( get_theme_mod( 'butcher_meatshop_header_info_email','info@example.com' ) ); ?>">
                                                <i class="<?php echo esc_attr(get_theme_mod('butcher_meatshop_header_email_icon','fas fa-envelope')); ?>"></i><span><?php echo esc_html( get_theme_mod( 'butcher_meatshop_header_info_email','info@example.com' ) ); ?></span>
                                            </a>
                                        </span>
                                    </span>
                                </span>
                            <?php endif; ?>
                        </div>
                        <div class="top-center">
                        </div>
                        <div class="top-right">
                           <?php if (get_theme_mod('butcher_meatshop_header_info_time','Mon-Sat 8am - 6pm')): ?>
                                <span class="address">
                                    <i class="<?php echo esc_attr(get_theme_mod('butcher_meatshop_header_time_icon','far fa-clock')); ?>"></i><span class="main-head"><?php echo esc_html(get_theme_mod('butcher_meatshop_header_info_time','Mon-Sat 8am - 6pm')); ?></span>
                                </span>
                            <?php endif; ?>
                            <?php if (class_exists('woocommerce')) : ?>
                                <span class="top-myacc">
                                    <?php if (is_user_logged_in()) : ?>
                                        <a href="<?php echo esc_url(get_permalink(get_option('woocommerce_myaccount_page_id'))); ?>" aria-label="<?php esc_attr_e('My Account', 'butcher-meatshop'); ?>">
                                            <i class="fas fa-download"></i>
                                            <span class="login-text"><?php esc_html_e('My Account', 'butcher-meatshop'); ?></span>
                                        </a>
                                    <?php else : ?>
                                        <a href="<?php echo esc_url(get_permalink(get_option('woocommerce_myaccount_page_id'))); ?>" aria-label="<?php esc_attr_e('My Account', 'butcher-meatshop'); ?>">
                                            <i class="fas fa-download"></i><br>
                                            <span class="login-text"><?php esc_html_e('My Account', 'butcher-meatshop'); ?></span>
                                        </a>
                                    <?php endif; ?>
                                </span>
                            <?php endif; ?>
                            <?php if (class_exists('woocommerce')): ?>
                                <span class="top-cart">
                                    <span class="main-woo-box">
                                        <span class="cart-no-box">
                                            <a href="<?php echo esc_url(wc_get_cart_url()); ?>" title="<?php esc_attr_e('Shopping Cart', 'butcher-meatshop'); ?>">
                                                <i class="fas fa-shopping-cart"></i>
                                                <span class="screen-reader-text"><?php esc_html_e('Shopping Cart', 'butcher-meatshop'); ?></span>
                                                <span class="cart-value"><?php echo esc_html(WC()->cart->get_cart_contents_count()); ?></span>
                                            </a>
                                        </span>
                                    </span>
                                </span>
                            <?php endif; ?>
                        </div>
                        <div class="search-outer">
                            <div class="serach_inner">
                                <?php get_search_form(); ?>
                            </div>
                            <button type="button" class="search-close">
                                <?php echo esc_html__('X', 'butcher-meatshop'); ?>
                            </button>
                        </div>
                    </div>
                </div>
            </div>

            <?php 
            // Check if header image is set
            $butcher_meatshop_has_header_image = has_header_image();
            $butcher_meatshop_header_image_url = $butcher_meatshop_has_header_image ? esc_url( get_header_image() ) : ''; 
            ?>
                <div class="header-menu-box" style="background-image: url('<?php echo $butcher_meatshop_header_image_url; ?>'); background-repeat: no-repeat;background-size: cover;">
                    <div class="container menucontent">
                        <div class="flex-row">
                            <!-- Left Menu -->
                            <div class="nav-menu-header-left">
                                <nav id="site-navigation" class="main-navigation">
                                    <?php
                                        wp_nav_menu( array(
                                            'theme_location' => 'left-menu',
                                            'menu_id'        => 'primary-menu',
                                            'menu_class'     => 'primary-menu-with-dots',
                                        ) );
                                    ?>
                                </nav>
                            </div>
                            <!-- Logo and Site Branding -->
                            <div class="nav-menu-header-center">
                                <div class="logo_outer_box">
                                    <div class="logo_outer">
                                        <div class="site-branding">
                                            <?php
                                            the_custom_logo();
                                            if ( is_front_page() && is_home() ) :
                                                if ( get_theme_mod( 'butcher_meatshop_site_title_text', true ) ) : ?>
                                                    <h1 class="site-title">
                                                        <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>
                                                    </h1>
                                                <?php endif;
                                            else :
                                                if ( get_theme_mod( 'butcher_meatshop_site_title_text', true ) ) : ?>
                                                    <p class="site-title">
                                                        <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>
                                                    </p>
                                                <?php endif;
                                            endif;

                                            $butcher_meatshop_description = get_bloginfo( 'description', 'display' );
                                            if ( $butcher_meatshop_description || is_customize_preview() ) :
                                                if ( get_theme_mod( 'butcher_meatshop_site_tagline_text', false ) ) : ?>
                                                    <p class="site-description"><?php echo esc_html( $butcher_meatshop_description ); ?></p>
                                                <?php endif;
                                            endif; ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- Right Menu -->
                            <span class="nav-menu-header-right">
                                <nav id="site-navigation" class="main-navigation">
                                    <?php
                                        wp_nav_menu( array(
                                            'theme_location' => 'right-menu',
                                            'menu_id'        => 'primary-menu',
                                            'menu_class'     => 'primary-menu-with-dots',
                                        ) );
                                    ?>
                                </nav>
                            </span>
                        </div>
                    </div>
                </div>
            <!-- Responsive Menu -->
            <nav id="site-navigation" class="main-navigation resp-nav responsive-menus">
                <button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false">
                    <span class="screen-reader-text"><?php esc_html_e( 'Primary Menu', 'butcher-meatshop' ); ?></span>
                    <i class="fas fa-bars"></i>
                </button>
                <?php
                wp_nav_menu( array(
                    'theme_location' => 'responsive-menu',
                    'menu_id'        => 'primary-menu responsive-menu',
                ) );
                ?>
            </nav>
        </div>
    </header>
</div>