<?php
/**
 * The header for our theme
 *
 * @package Rev Digital Products
 */
?>
<!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', 'rev-digital-products' ); ?></a>

    <?php
    $rev_digital_products_preloader_wrap = absint( get_theme_mod( 'rev_digital_products_enable_preloader', 0 ) );
    if ( $rev_digital_products_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">
                <div class="top-head">
                    <div class="container">
                        <div class="flex-row">
                            <div class="top-left">
                                <?php if (class_exists('WooCommerce')): ?>
                                    <a class="my-acc" href="<?php echo esc_url(get_permalink(get_option('woocommerce_myaccount_page_id'))); ?>">
                                        <i class="<?php echo is_user_logged_in() ? 'fas' : 'far'; ?> fa-user" aria-hidden="true"></i> <span class="my-account-text"><?php esc_html_e('My Account', 'rev-digital-products'); ?></span>
                                    </a>
                                <?php endif; ?>

                                <span class="help-button">
                                    <?php if (get_theme_mod('rev_digital_products_header_button_link','#') || get_theme_mod('rev_digital_products_header_button_text', 'Help')): ?>
                                        <a href="<?php echo esc_url(get_theme_mod('rev_digital_products_header_button_link','#')); ?>"><i class="fas fa-question-circle"></i> <?php echo esc_html(get_theme_mod('rev_digital_products_header_button_text', 'Help')); ?></a>
                                    <?php endif; ?>
                                </span>
                                <?php if ( get_theme_mod( 'rev_digital_products_header_info_email','digital@example.com' ) ) : ?>
                                    <span class="contact-info">
                                        <span class="main-box email">
                                            <span class="main-head">
                                                <a href="mailto:<?php echo esc_attr( get_theme_mod( 'rev_digital_products_header_info_email','digital@example.com' ) ); ?>">
                                                    <i class="fas fa-envelope-open-text"></i> <?php echo esc_html( get_theme_mod( 'rev_digital_products_header_info_email','digital@example.com' ) ); ?>
                                                </a>
                                            </span>
                                        </span>
                                    </span>
                                <?php endif; ?>
                            </div>
                            <div class="top-right">
                                <span class="social-media">
                                    <?php if ( get_theme_mod( 'rev_digital_products_facebook_link_option','#' ) ) : ?>
                                        <a href="<?php echo esc_url( get_theme_mod( 'rev_digital_products_facebook_link_option','#' ) ); ?>" target="_blank" rel="noopener noreferrer">
                                            <i class="fab fa-facebook"></i>
                                        </a>
                                    <?php endif; ?>
                                    <?php if ( get_theme_mod( 'rev_digital_products_twitter_link_option','#' ) ) : ?>
                                        <a href="<?php echo esc_url( get_theme_mod( 'rev_digital_products_twitter_link_option','#' ) ); ?>" target="_blank" rel="noopener noreferrer">
                                            <i class="fab fa-twitter"></i>
                                        </a>
                                    <?php endif; ?>
                                    <?php if ( get_theme_mod( 'rev_digital_products_instagram_link_option','#' ) ) : ?>
                                        <a href="<?php echo esc_url( get_theme_mod( 'rev_digital_products_instagram_link_option','#' ) ); ?>" target="_blank" rel="noopener noreferrer">
                                            <i class="fab fa-instagram"></i>
                                        </a>
                                    <?php endif; ?>
                                    <?php if ( get_theme_mod( 'rev_digital_products_linked_link_option','#' ) ) : ?>
                                        <a href="<?php echo esc_url( get_theme_mod( 'rev_digital_products_linked_link_option','#' ) ); ?>" target="_blank" rel="noopener noreferrer">
                                            <i class="fab fa-linkedin-in"></i>
                                        </a>
                                    <?php endif; ?>
                                    <?php if ( get_theme_mod( 'rev_digital_products_pinterest_link_option','#' ) ) : ?>
                                        <a href="<?php echo esc_url( get_theme_mod( 'rev_digital_products_pinterest_link_option','#' ) ); ?>" target="_blank" rel="noopener noreferrer">
                                            <i class="fab fa-pinterest-p"></i>
                                        </a>
                                    <?php endif; ?>
                                </span>
                                
                            </div>
                        </div>
                    </div>
                </div>
                <?php 
                $rev_digital_products_has_header_image = has_header_image();
                $rev_digital_products_header_image_url = $rev_digital_products_has_header_image ? esc_url( get_header_image() ) : '';
                ?>
                <div class="middle-head" style="background-image: url('<?php echo $rev_digital_products_header_image_url; ?>'); background-repeat: no-repeat; background-size: cover;">
                    <div class="header-menu-box">
                        <div class="container menu <?php echo esc_attr( get_theme_mod( 'rev_digital_products_enable_sticky_header', false ) ? 'sticky-header' : '' ); ?>">
                            <div class="flex-row">
                                <div class="middle-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( 'rev_digital_products_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( 'rev_digital_products_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;

                                        $rev_digital_products_description = get_bloginfo( 'description', 'display' );
                                        if ( $rev_digital_products_description || is_customize_preview() ) :
                                            if ( get_theme_mod( 'rev_digital_products_site_tagline_text', false ) ) : ?>
                                                <p class="site-description"><?php echo esc_html( $rev_digital_products_description ); ?></p>
                                            <?php endif;
                                        endif; ?>
                                    </div>
                                </div>
                                <div class="middle-center">
                                    <div class="nav-menu-header-right">
                                        <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', 'rev-digital-products' ); ?></span>
                                                <i class="fas fa-bars"></i>
                                            </button>
                                            <?php
                                            wp_nav_menu( array(
                                                'theme_location' => 'menu-1',
                                                'menu_id'        => 'primary-menu',
                                            ) );
                                            ?>
                                        </nav>
                                    </div>
                                    <?php if ( get_theme_mod( 'rev_digital_products_header_search', true ) == 1 ) : ?>
                                            <span class="search-bar">
                                                <button type="button" class="open-search"><i class="fas fa-search"></i></button>
                                            </span>
                                    <?php endif; ?>
                                </div>
                                    <div class="search-outer">
                                        <div class="inner_searchbox">
                                            <?php get_search_form(); ?>
                                        </div>
                                        <button type="button" class="search-close"><i class="fas fa-window-close"></i></button>
                                    </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="bottom-head">
                    <div class="container">
                        <div class="flex-row">
                            <div class="bottom-left cat-box">
                                <?php if(class_exists('woocommerce')){ ?>
                                    <button class="category-button"><span class="cat-text"><?php echo esc_html(get_theme_mod('rev_digital_products_category_text','ALL CATEGORY','rev-digital-products')); ?></span><span class="cat-icon"><i class="fa fa-bars" aria-hidden="true"></i></span></button>
                                    <div class="cat-dropdown">
                                        <?php
                                          $args = array(
                                            'number'     => get_theme_mod('rev_digital_products_product_category_number'),
                                            'orderby'    => 'title',
                                            'order'      => 'ASC',
                                            'hide_empty' => 0,
                                            'parent'  => 0
                                          );
                                          $rev_digital_products_product_categories = get_terms( 'product_cat', $args );
                                          $rev_digital_products_count = count($rev_digital_products_product_categories);
                                          if ( $rev_digital_products_count > 0 ){
                                            foreach ( $rev_digital_products_product_categories as $product_category ) {
                                              $rev_digital_products_cat_id   = $product_category->term_id;
                                              $cat_link = get_category_link( $rev_digital_products_cat_id );
                                              if ($product_category->category_parent == 0) { ?>
                                            <li class="drp_dwn_menu"><a href="<?php echo esc_url(get_term_link( $product_category ) ); ?>">
                                            <?php
                                          }
                                            echo esc_html( $product_category->name ); ?></a></li>
                                            <?php
                                            }
                                          }
                                        ?>
                                    </div>
                                <?php }?>
                            </div>
                            <div class="bottom-center main-search">
                                <?php if (class_exists('WooCommerce')): ?> 
                                    <div class="product-search">
                                        <form method="get" class="woocommerce-product-search" action="<?php echo esc_url(home_url('/')); ?>">
                                            <label for="product-search-field" class="screen-reader-text"><?php esc_html_e('Search for:', 'rev-digital-products'); ?></label>
                                            <input type="search" id="product-search-field" class="search-field" placeholder="<?php esc_attr_e('Search products...', 'rev-digital-products'); ?>" value="<?php echo esc_attr(get_search_query()); ?>" name="s" />
                                            <input type="hidden" name="post_type" value="product" />
                                            <button type="submit">
                                                <span class="search-icon" aria-hidden="true"><i class="fas fa-search"></i></span>
                                                <span class="screen-reader-text"><?php esc_html_e('Search', 'rev-digital-products'); ?></span>
                                            </button>
                                        </form>
                                    </div>
                                <?php endif; ?>
                            </div>
                            <div class="bottom-right">
                                <?php if (class_exists('WooCommerce')): ?> 
                                    <span class="product-cart text-center position-relative pe-2">
                                        <a href="<?php echo esc_url(wc_get_cart_url()); ?>" title="<?php esc_attr_e('Shopping cart', 'rev-digital-products'); ?>">
                                            <i class="fas fa-shopping-bag" aria-hidden="true"></i>
                                        <?php 
                                        $rev_digital_products_cart_count = WC()->cart->get_cart_contents_count(); 
                                        if ($rev_digital_products_cart_count > 0): ?>
                                            <span class="cart-count"><?php echo esc_html($rev_digital_products_cart_count); ?></span>
                                        <?php endif; ?>
                                        </a>
                                    </span>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
    </header>
</div>
<?php wp_footer(); ?>
</body>
</html>