<?php
/**
 * The header for our theme
 *
 * @package Carpets and Rugs
 */
?>
<!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', 'carpets-and-rugs' ); ?></a>

    <?php
    $carpets_and_rugs_preloader_wrap = absint( get_theme_mod( 'carpets_and_rugs_enable_preloader', 0 ) );
    if ( $carpets_and_rugs_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">
            <div class="header-info-box">
                <?php if (get_theme_mod('carpets_and_rugs_show_topbar', 1)) : ?>
                    <div class="top-head">
                        <div class="container">
                            <div class="flex-row">
                                <div class="top-left">
                                    <div class="top-header">
                                        <?php if (!empty(get_theme_mod('carpets_and_rugs_order_shipping_link','#')) || !empty(get_theme_mod('carpets_and_rugs_order_shipping_text','FREE SHIPPING'))) : ?>
                                          <span class="return-btn">
                                            <a href="<?php echo esc_url(get_theme_mod('carpets_and_rugs_order_shipping_link', '#')); ?>">
                                              <?php if (!empty(get_theme_mod('carpets_and_rugs_order_shipping_text','FREE SHIPPING'))) : ?>
                                                <?php echo esc_html(get_theme_mod('carpets_and_rugs_order_shipping_text', 'FREE SHIPPING')); ?>
                                              <?php endif; ?>
                                            </a>
                                          </span>
                                        <?php endif; ?>
                                        <?php if (get_theme_mod('carpets_and_rugs_delivery_text') !== '') : ?>
                                          <span class="mb-0"><?php echo esc_html(get_theme_mod('carpets_and_rugs_delivery_text', 'on orders over $99. This offer is valid on all store items.')); ?></span>
                                        <?php endif; ?>
                                      </div>
                                </div>
                                <div class="top-right">
                                    <?php if ( get_theme_mod( 'carpets_and_rugs_header_info_phone','123 111 7895' ) ) : ?>
                                        <span class="contact-info">
                                            <span class="main-box phone">
                                                <span class="main-head">
                                                    <a href="tel:<?php echo esc_attr( get_theme_mod( 'carpets_and_rugs_header_info_phone','123 111 7895' ) ); ?>">
                                                        <i class="<?php echo esc_attr(get_theme_mod('carpets_and_rugs_header_phone_icon','fas fa-phone-alt')); ?>"></i><span><?php echo esc_html( get_theme_mod( 'carpets_and_rugs_header_info_phone','123 111 7895' ) ); ?></span>
                                                    </a>
                                                </span>
                                            </span>
                                        </span>
                                    <?php endif; ?>
                                    <?php if ( get_theme_mod( 'carpets_and_rugs_header_info_email','carpetstore@exmple.com' ) ) : ?>
                                        <span class="contact-info">
                                            <span class="main-box mail">
                                                <span class="main-head">
                                                    <a href="mailto:<?php echo esc_attr( get_theme_mod( 'carpets_and_rugs_header_info_email','carpetstore@exmple.com' ) ); ?>">
                                                        <i class="<?php echo esc_attr(get_theme_mod('carpets_and_rugs_header_mail_icon','far fa-envelope-open')); ?>"></i><span><?php echo esc_html( get_theme_mod( 'carpets_and_rugs_header_info_email','carpetstore@exmple.com' ) ); ?></span>
                                                    </a>
                                                </span>
                                            </span>
                                        </span>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php endif; ?>

                <?php 
                    $carpets_and_rugs_has_header_image = has_header_image();

                    if ( $carpets_and_rugs_has_header_image ) {
                        $carpets_and_rugs_header_image_url = esc_url( get_header_image() );
                    } else {
                        $carpets_and_rugs_header_image_url = '';
                    }
                ?>
                
                <div class="header-menu-box" style="background-image: url('<?php echo $carpets_and_rugs_header_image_url; ?>'); background-repeat: no-repeat; background-size: cover;">
                    <div class="container menucontent">
                        <div class="flex-row">
                            <div class="nav-menu-header-left">
                                <div class="site-branding">
                                    <?php
                                    if ( function_exists( 'the_custom_logo' ) ) {
                                        the_custom_logo();
                                    }
                                    if ( is_front_page() && is_home() ) :
                                        if ( get_theme_mod( 'carpets_and_rugs_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( 'carpets_and_rugs_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;
                                    $carpets_and_rugs_description = get_bloginfo( 'description', 'display' );
                                    if ( $carpets_and_rugs_description || is_customize_preview() ) :
                                        if ( get_theme_mod( 'carpets_and_rugs_site_tagline_text', false ) ) : ?>
                                            <p class="site-description"><?php echo esc_html( $carpets_and_rugs_description ); ?></p>
                                        <?php endif;
                                    endif; ?>
                                </div>
                            </div>
                            <div class="nav-menu-header-center">
                                <div class="product-search">
                                    <div class="search_inner my-3 my-md-0">
                                        <?php if (class_exists('WooCommerce')) : ?>
                                            <?php get_product_search_form(); ?>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </div>
                            <div class="nav-menu-header-right">
                                <div class="header-details">
                                    <p class="mb-0">
                                        <?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'))); ?>" aria-label="<?php esc_attr_e('My Account', 'carpets-and-rugs'); ?>">
                                                    <i class="fas fa-user"></i>
                                                    <span class="login-text"><?php esc_html_e('My Account', 'carpets-and-rugs'); ?></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', 'carpets-and-rugs'); ?>">
                                                    <i class="fas fa-user"></i><br>
                                                    <span class="login-text"><?php esc_html_e('My Account', 'carpets-and-rugs'); ?></span>
                                                </a>
                                            <?php endif; ?>
                                        <?php endif; ?>
                                    </p>
                                    <p class="mb-0">
                                        <?php if (class_exists('woocommerce')) : ?>
                                            <span class="product-cart text-center">
                                                <a href="<?php echo esc_url(wc_get_cart_url()); ?>" title="<?php esc_attr_e('Shopping Cart', 'carpets-and-rugs'); ?>" aria-label="<?php esc_attr_e('My Cart', 'carpets-and-rugs'); ?>">
                                                    <i class="fas fa-shopping-basket"></i>
                                                    <?php 
                                                    $carpets_and_rugs_cart_count = WC()->cart->get_cart_contents_count(); 
                                                    if ($carpets_and_rugs_cart_count > 0) : ?>
                                                        <span class="cart-count"><?php echo esc_html($carpets_and_rugs_cart_count); ?></span>
                                                    <?php endif; ?>
                                                </a>
                                            </span>
                                        <?php endif; ?>
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>                
                <div class="lower-header  <?php echo esc_attr( get_theme_mod( 'carpets_and_rugs_enable_sticky_header', false ) ? 'sticky-header' : '' ); ?>">
                    <nav id="site-navigation" class="main-navigation">
                        <button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false">
                            <span class="screen-reader-text"><?php esc_html_e( 'Primary Menu', 'carpets-and-rugs' ); ?></span>
                            <i class="fas fa-bars"></i>
                        </button>
                        <?php
                        wp_nav_menu( array(
                            'theme_location' => 'menu-1',
                            'menu_id'        => 'primary-menu',
                        ) );
                        ?>
                    </nav>
                </div>
            </div>
        </div>
    </header>
</div>