<?php
$current_page = basename($_SERVER['PHP_SELF']);

// রিসিভড অর্ডারের সংখ্যা চেক করার জন্য (database connection $pdo থাকা অবস্থায়)
$received_count = 0;
if (isset($pdo)) {
    $stmt = $pdo->query("SELECT COUNT(*) FROM orders WHERE status = 'received'");
    $received_count = $stmt->fetchColumn();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Panel</title>
    
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">

    <style>
        :root {
            --brand-main: #230133; 
            --brand-hover: #3b0354;
            --brand-active: #4a026b;
            --bs-body-bg: #f4f6f9;
            --sidebar-width: 260px;
            --sidebar-link-color: #d1cfd4;
            --sidebar-link-hover-color: #ffffff;
            --info-color: #0dcaf0;
        }

        body {
            font-family: 'Poppins', sans-serif;
            background-color: var(--bs-body-bg);
            transition: margin-left .3s ease;
        }

        /* --- নোটিফিকেশন অ্যানিমেশন --- */
        @keyframes pulse-notify {
            0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(13, 202, 240, 0.7); }
            70% { transform: scale(1.01); box-shadow: 0 0 0 10px rgba(13, 202, 240, 0); }
            100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(13, 202, 240, 0); }
        }
        .order-notification {
            background: #fff;
            border-left: 5px solid var(--info-color);
            border-radius: 8px;
            animation: pulse-notify 2s infinite;
            display: flex;
            align-items: center;
            padding: 12px 20px;
            margin-bottom: 20px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.05);
        }

        /* Sidebar Styling */
        .sidebar {
            width: var(--sidebar-width);
            background-color: var(--brand-main);
            position: fixed;
            top: 0;
            bottom: 0;
            left: 0;
            transition: left .3s ease;
            z-index: 1000;
            box-shadow: 4px 0 10px rgba(0,0,0,0.1);
        }

        .sidebar-brand {
            color: white;
            font-weight: 700;
            padding: 2rem 1.5rem;
            font-size: 1.4rem;
            letter-spacing: 1px;
            border-bottom: 1px solid rgba(255,255,255,0.1);
            margin-bottom: 1rem;
        }

        .sidebar-nav .nav-link {
            color: var(--sidebar-link-color);
            padding: 0.85rem 1.5rem;
            font-weight: 400;
            border-radius: 0;
            transition: all 0.3s;
            display: flex;
            align-items: center;
        }

        .sidebar-nav .nav-link i {
            font-size: 1.2rem;
            margin-right: 12px;
        }

        .sidebar-nav .nav-link:hover {
            color: var(--sidebar-link-hover-color);
            background-color: var(--brand-hover);
            padding-left: 2rem;
        }

        .sidebar-nav .nav-link.active {
            color: #ffffff;
            background-color: var(--brand-active);
            border-left: 4px solid #fff;
            font-weight: 600;
        }

        /* Topbar Styling */
        .topbar {
            background: #fff;
            padding: 0.8rem 1.5rem;
            box-shadow: 0 0.15rem 1.75rem 0 rgba(35, 1, 51, 0.1);
            margin-bottom: 1.5rem;
            border-radius: 10px;
            display: flex;
            align-items: center;
        }

        #sidebarToggle {
            font-size: 1.6rem;
            cursor: pointer;
            color: var(--brand-main);
            transition: 0.2s;
        }

        #sidebarToggle:hover {
            color: var(--brand-hover);
        }

        .main-content {
            margin-left: var(--sidebar-width);
            padding: 1.5rem;
            transition: margin-left .3s ease;
        }

        body.sidebar-collapsed .sidebar {
            left: calc(-1 * var(--sidebar-width));
        }
        body.sidebar-collapsed .main-content {
            margin-left: 0;
        }

        .logout-section {
            margin-top: auto;
            border-top: 1px solid rgba(255,255,255,0.1);
            padding: 1rem 0;
        }
    </style>
</head>
<body>

<div class="sidebar d-flex flex-column flex-shrink-0">
    <a href="index.php" class="sidebar-brand text-decoration-none d-flex align-items-center">
        <i class="bi bi-shield-lock-fill me-2"></i>
        <span>Admin Panel</span>
    </a>

    <ul class="nav nav-pills flex-column mb-auto sidebar-nav">
        <li class="nav-item">
            <a href="index.php" class="nav-link <?php if($current_page == 'index.php') echo 'active'; ?>">
                <i class="bi bi-speedometer2"></i> Dashboard
            </a>
        </li>
        <li>
            <a href="users.php" class="nav-link <?php if($current_page == 'users.php') echo 'active'; ?>">
                <i class="bi bi-people"></i> Users
            </a>
        </li>
        <li>
            <a href="recharges.php" class="nav-link <?php if($current_page == 'recharges.php') echo 'active'; ?>">
                <i class="bi bi-wallet2"></i> Recharges
            </a>
        </li>
        <li>
            <a href="orders.php" class="nav-link <?php if($current_page == 'orders.php') echo 'active'; ?>">
                <i class="bi bi-cart-check"></i> Orders 
                <?php if($received_count > 0): ?>
                    <span class="badge rounded-pill bg-info text-dark ms-auto"><?php echo $received_count; ?></span>
                <?php endif; ?>
            </a>
        </li>
        <li>
            <a href="services.php" class="nav-link <?php if($current_page == 'services.php') echo 'active'; ?>">
                <i class="bi bi-box-seam"></i> Services
            </a>
        </li>
        <li>
            <a href="subcategories.php" class="nav-link <?php if($current_page == 'subcategories.php') echo 'active'; ?>">
                <i class="bi bi-layers"></i> Subcategories
            </a>
        </li>
         <li>
            <a href="site_info.php" class="nav-link <?php if($current_page == 'site_info.php') echo 'active'; ?>">
                <i class="bi bi-gear-wide-connected"></i> Site Info Change
            </a>
        </li>
    </ul>

    <div class="logout-section">
        <a href="logout.php" class="nav-link text-white ps-4">
            <i class="bi bi-box-arrow-right me-2"></i> Logout
        </a>
    </div>
</div>

<div class="main-content">
    <nav class="topbar">
        <i class="bi bi-list" id="sidebarToggle"></i>
        <h5 class="ms-3 mb-0 fw-bold d-none d-md-block" style="color: var(--brand-main);">অ্যাডমিন কন্ট্রোল সেন্টার</h5>
    </nav>

    <!-- 🔔 নোটিফিকেশন মেসেজ: শুধুমাত্র 'Received' অর্ডার থাকলে দেখাবে -->
    <?php if ($received_count > 0): ?>
        <div class="order-notification">
            <i class="bi bi-bell-fill text-info fs-4 me-3"></i>
            <div class="flex-grow-1">
                <span class="fw-bold text-dark">নতুন অর্ডার নোটিশ:</span> 
                বর্তমানে <span class="badge bg-info text-dark"><?php echo $received_count; ?>টি</span> অর্ডার <strong>Received</strong> অবস্থায় আছে। দ্রুত প্রসেস করুন।
            </div>
            <a href="orders.php?tab=received" class="btn btn-sm btn-info text-dark fw-bold shadow-sm">অর্ডার দেখুন</a>
        </div>
    <?php endif; ?>
    
    <?php show_flash(); ?>