<?php
$email = $_SESSION['alogin'];
$sql = "SELECT * from users where email = (:email);";
$query = $dbh->prepare($sql);
$query->bindParam(':email', $email, PDO::PARAM_STR);
$query->execute();
$result = $query->fetch(PDO::FETCH_OBJ);
$cnt = 1;
$_SESSION['user_id']=$result->id;
$bbbb = $result->balance;
?>
<!--  Header Start -->
<header class="app-header" style="background-color: #f0f0f0;">
    <nav class="navbar navbar-expand-lg navbar-light">
        <ul class="navbar-nav">
            <li class="nav-item d-block d-xl-none">
                <a class="nav-link sidebartoggler nav-icon-hover" id="headerCollapse" href="javascript:void(0)">
                    <i class="ti ti-menu-2" style="font-size: 24px; color: #333333;"></i>
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link nav-icon-hover notifDiv" id="" href="#" style="position: relative;">
                    <i class="ti ti-bell-ringing" style="font-size: 24px; color: #333333;"></i>
                    <div class="notification bg-danger rounded-circle" style="position: absolute; top: 10px; right: 10px; width: 10px; height: 10px; background-color: #ff0000; border-radius: 50%;"></div>
                    <div class="alert alert-primary notifText" style="position: absolute; top: 40px; right: 10px; width: 150px; line-height: 1.5rem; padding: 0.5rem; display: none; background-color: #ffffff; border-radius: 10px;" role="alert">আপনার সাইন/সার্ভার কপি অর্ডার ডেলিভারি করা হয়েছে।</div>
                </a>
            </li>
        </ul>
        <div class="navbar-collapse justify-content-end px-0" id="navbarNav">
            <ul class="navbar-nav flex-row ms-auto align-items-center justify-content-end">
                <a href="recharge.php" target="_blank" class="btn btn-primary" style="background-color: #333333; color: #ffffff; padding: 10px 20px; border-radius: 10px;"><?php echo htmlentities($result->balance); ?> টাকা</a>
                <li class="nav-item dropdown">
                    <a class="nav-link nav-icon-hover" href="javascript:void(0)" id="drop2" data-bs-toggle="dropdown" aria-expanded="false">
                        <img src="https://i.ibb.co/ymHVnLQw/image.jpg" alt="" width="35" height="35" class="rounded-circle" style="border: 2px solid #e89910;">
                    </a>
                    <div class="dropdown-menu dropdown-menu-end dropdown-menu-animate-up" aria-labelledby="drop2" style="background-color: #f0f0f0; padding: 20px; border-radius: 20px;">
                        <div class="message-body">
                            <a href="profile.php" class="d-flex align-items-center gap-2 dropdown-item" style="padding: 10px; border-radius: 10px; background-color: #ffffff;">
                                <i class="ti ti-user fs-6" style="font-size: 24px; color: #333333;"></i>
                                <p class="mb-0 fs-3" style="font-size: 18px; color: #333333;"> প্রোফাইল</p>
                            </a>
                            <a href="change-password.php" class="d-flex align-items-center gap-2 dropdown-item" style="padding: 10px; border-radius: 10px; background-color: #ffffff;">
                                <i class="ti ti-key fs-6" style="font-size: 24px; color: #333333;"></i>
                                <p class="mb-0 fs-3" style="font-size: 18px; color: #333333;"> পাসওয়ার্ড পরিবর্তন</p>
                            </a>
                            <a href="logout.php" class="btn btn-outline-primary mx-3 mt-2 d-block" style="background-color: #333333; color: #ffffff; padding: 10px 20px; border-radius: 10px;">লগ আউট</a>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
    </nav>
</header>
<script>
    var notifIcon = $(".notifIcon");
    var notifDiv = $(".notifDiv");
    setTimeout(() => {
        $.ajax({
            type: "POST",
            url: "lib/notification.php",
            data: {email:'<?php echo $_SESSION['alogin'] ?>'},
            dataType:"json",
            success: function (response) {
                if(response.sign != 0 || response.server != 0){
                    notifDiv.empty();
                    notifDiv.append("<i class=\"ti ti-bell-ringing\"></i>");
                    notifDiv.append("<div class=\"notification bg-danger rounded-circle\"></div>");
                    notifDiv.append("<div class=\"alert alert-primary notifText\" style=\"position: absolute;top: 3.5rem;width: 15rem;line-height: 1.5rem;padding: .5rem;display:block;\" role=\"alert\">আপনার সাইন/সার্ভার কপি অর্ডার ডেলিভারি করা হয়েছে।</div>");
                
                }else{
                    notifDiv.empty();
                    notifDiv.append("<i class=\"ti ti-bell-ringing\"></i>");
                } 
            }
        });
    }, 50);
</script>
