<?php
require('connection.inc.php');

$cartCount = 0;

if (isset($_SESSION['user_id'])) {
    $user_id = $_SESSION['user_id'];
    $stmt = $conn->prepare("SELECT COUNT(*) FROM (SELECT 1 FROM cart WHERE user_id = ? GROUP BY product_id, unit_id) AS distinct_items");
    $stmt->bind_param("i", $user_id);
    $stmt->execute();
    $stmt->bind_result($cartCount);
    $stmt->fetch();
    $stmt->close();
}
?>


<header>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
         <div class="header__top theme-bg-1 d-none d-md-block ps-5 pe-5">
            <div class="container-fluid">
               <div class="row align-items-center">
                  <div class="col-lg-6 col-md-12">
                     <div class="header__top-left">
                        <span>Best quality berries? Let us be your first and last stop for it.</span>
                     </div> 
                  </div>
                  <div class="col-lg-6 col-md-12">
  <div class="d-flex justify-content-end align-items-center">
    <div class="text-white me-2">
    <?php
    if (isset($_SESSION['username'])) {
        echo '<a href="index.php">Welcome, ' . htmlspecialchars($_SESSION['username']) . '</a>';
    } else {
        echo '<a href="log-in.php">Login/Register</a>';
    }
    ?>
    </div>
    <div class="header__top-right d-flex align-items-center gap-3">
      <a href="https://www.facebook.com/profile.php?id=61550353618807" target="_blank" class="text-white"><i class="fab fa-facebook-f"></i></a>
      <a href="https://x.com/ethnic_foods" target="_blank" class="text-white"><i class="fab fa-twitter"></i></a>
      <a href="https://www.youtube.com/@EthnicFoodProduct" target="_blank" class="text-white"><i class="fab fa-youtube"></i></a>
      <a href="https://www.instagram.com/ethnicfoodproduct/" target="_blank" class="text-white"><i class="fab fa-instagram"></i></a>
    </div>
  </div>
</div>

               </div>
            </div>
         </div>
         <div id="header-sticky" class="header__main-area d-none d-xl-block p-2">
            <div class="container-fluid">
               <div class="header__for-megamenu p-relative">
                  <div class="row align-items-center">
                     <div class="col-xl-3">
                        <div class="header__logo ps-5">
                           <a href="index.php"><img src="assets/img/allnew/logo.png" alt="logo"></a>
                        </div>
                     </div>
                     <div class="col-xl-4">
                        <div class="header__menu main-menu text-center">
                           <nav id="mobile-menu">
                              <ul>
                                 <li >
                                    <a href="index.php">Home</a>
                                 </li>
                                 <li><a href="product.php">Shop</a></li>
                                 <li><a href="about.php">About Us</a></li>
                                 <li><a href="contact.php">Contact Us</a></li>
                                 <li>
                                    <a href="blog.php">Blog</a>
                                 </li>
                              </ul>
                           </nav>
                        </div>
                     </div>
                     <div class="col-xl-5">
                        <div class="header__info d-flex align-items-center pe-5">
                          <div class="header__info-user tpcolor__yellow ml-10">
                            <?php if (isset($_SESSION['username'])): ?>
                            <a href="javascript:void(0)" class="user-icon" onclick="toggleDropdown()">
                                <i class="icon-user"></i>
                            </a>
                            <?php endif; ?>
                            <div id="dropdownMenu" class="dropdown-menu">
                                <a href="order.php" class="dropdown-item">Order Page</a>
                                <a href="wishlist.php" class="dropdown-item">Wishlist</a>
                                <a href="logout.php" class="dropdown-item">Logout</a>
                            </div>
                        </div>
<style>
    .dropdown-menu {
        display: none;
        position: absolute;
        background-color: #fff;
        border: 1px solid #ccc;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        z-index: 1000;
    }

    .dropdown-item {
        padding: 10px;
        text-decoration: none;
        color: #333;
        display: block;
    }

    .dropdown-item:hover {
        background-color: #f1f1f1;
    }
</style>
<script>
    function toggleDropdown() {
    const dropdown = document.getElementById("dropdownMenu");
    dropdown.style.display = (dropdown.style.display === "block") ? "none" : "block";
}

</script>
                          
<div class="header__info-cart tpcolor__oasis ml-10 tp-cart-toggle">
    <a href="cart.php"><i><img src="assets/img/icon/cart-1.svg" alt=""></i></a>
    <span><?php echo $cartCount; ?></span>
</div>

                        </div>
                     </div>
                  </div>
               </div>
            </div>
         </div>

         <!-- header-search -->
         <div class="tpsearchbar tp-sidebar-area">
            <button class="tpsearchbar__close"><i class="icon-x"></i></button>
            <div class="search-wrap text-center">
                <div class="container">
                    <div class="row justify-content-center">
                        <div class="col-6 pt-100 pb-100">
                            <h2 class="tpsearchbar__title">What Are You Looking For?</h2>
                            <div class="tpsearchbar__form">
                                <form action="#">
                                    <input type="text" name="search" placeholder="Search Product...">
                                    <button class="tpsearchbar__search-btn"><i class="icon-search"></i></button>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
         </div>
         <div class="search-body-overlay"></div>
         <!-- header-search-end -->

         <!-- header-cart-start -->
        
         <div class="cartbody-overlay"></div>
         <!-- header-cart-end -->

         <!-- mobile-menu-area -->
         <div id="header-sticky-2" class="tpmobile-menu d-xl-none">
            <div class="container-fluid">
               <div class="row align-items-center">
                  <div class="col-lg-4 col-md-4 col-3 col-sm-3">
                     <div class="mobile-menu-icon">
                        <button class="tp-menu-toggle"><i class="icon-menu1"></i></button>
                     </div>
                  </div>
                  <div class="col-lg-4 col-md-4 col-6 col-sm-4">
                     <div class="header__logo text-center">
                        <a href="index.php"><img src="assets/img/allnew/logo.png" alt="logo"></a>
                     </div>
                  </div>
                  <div class="col-lg-4 col-md-4 col-3 col-sm-5">
                     <div class="header__info d-flex align-items-center">
                        <div class="header__info-search tpcolor__purple ml-10 d-none d-sm-block">
                           <button class="tp-search-toggle"><i class="icon-search"></i></button>
                        </div>
                        <div class="header__info-user tpcolor__yellow ml-10 d-none d-sm-block">
                           <a href="#"><i class="icon-user"></i></a>
                        </div>
                       
                        <div class="header__info-cart tpcolor__oasis ml-10 tp-cart-toggle">
                           <a href="cart.php"><button><i><img src="assets/img/icon/cart-1.svg" alt=""></i>
                            
                           </button></a>
                            
                           </button>
                        </div>
                     </div>
                  </div>
               </div>
            </div>
         </div>
         <div class="body-overlay"></div>
         <!-- mobile-menu-area-end -->

         <!-- sidebar-menu-area -->
         <div class="tpsideinfo">
            <button class="tpsideinfo__close">Close<i class="fal fa-times ml-10"></i></button>
            <div class="tpsideinfo__search text-center pt-35">
               <span class="tpsideinfo__search-title mb-20">What Are You Looking For?</span>
               <form action="#">
                  <input type="text" placeholder="Search Products...">
                  <button><i class="icon-search"></i></button>
               </form>
            </div>
            <div class="tpsideinfo__nabtab">
               
                <div class="tab-content" id="pills-tabContent">
                  <div class="tab-pane fade show active" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab" tabindex="0">
                     <div class="mobile-menu"></div>
                  </div>
                  <div class="tab-pane fade" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab" tabindex="0">
                     <div class="tpsidebar-categories">
                        <ul>
                           <li><a href="shop-details.php">Dairy Farm</a></li>
                           <li><a href="shop-details.php">Healthy Foods</a></li>
                           <li><a href="shop-details.php">Lifestyle</a></li>
                           <li><a href="shop-details.php">Organics</a></li>
                           <li><a href="shop-details.php">Photography</a></li>
                           <li><a href="shop-details.php">Shopping</a></li>
                           <li><a href="shop-details.php">Tips & Tricks</a></li>
                        </ul>
                     </div>
                  </div>
                </div>
            </div>
            <div class="tpsideinfo__account-link">							
               <a href="log-in.php"><i class="icon-user icons"></i> Login / Register</a>
            </div>
            
         </div> 
         <!-- sidebar-menu-area-end -->
      </header>