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

$pages_shop = ['users.php', 'products.php', 'categories.php', 'orders.php'];
$pages_money = ['coin_packages.php', 'transactions.php', 'coin_purchases.php'];
$pages_integrations = ['admob.php', 'telegram_bot.php', 'user_telegram_bot.php', 'smm_settings.php', 'email_settings.php', 'email_logs.php'];
$pages_system = ['settings.php', 'reports.php', 'backup.php', 'versions.php'];

$open_shop = in_array($current_page, $pages_shop, true);
$open_money = in_array($current_page, $pages_money, true);
$open_int = in_array($current_page, $pages_integrations, true);
$open_sys = in_array($current_page, $pages_system, true);
?>
<aside class="sidebar" id="adminSidebar" aria-label="منوی کناری">
    <div class="sidebar-header">
        <a href="index.php" class="sidebar-logo">
            <i class="fas fa-shield-alt"></i>
            <span>پنل مدیریت</span>
        </a>
        <button type="button" class="sidebar-close" id="adminSidebarClose" aria-label="بستن منو">
            <i class="fas fa-times"></i>
        </button>
    </div>
    <nav class="sidebar-nav">
        <ul class="nav-menu">
            <li class="nav-item">
                <a href="index.php" class="nav-link <?= $current_page === 'index.php' ? 'active' : '' ?>">
                    <i class="fas fa-tachometer-alt"></i><span>داشبورد</span>
                </a>
            </li>

            <li class="nav-heading"><span>فروشگاه</span></li>
            <li class="nav-item has-submenu <?= $open_shop ? 'open' : '' ?>">
                <a class="nav-link <?= $open_shop ? '' : 'collapsed' ?>" data-bs-toggle="collapse" href="#maSubShop" role="button" aria-expanded="<?= $open_shop ? 'true' : 'false' ?>">
                    <i class="fas fa-store"></i><span>فروشگاه</span><i class="fas fa-chevron-down nav-arrow"></i>
                </a>
                <ul class="nav-submenu collapse <?= $open_shop ? 'show' : '' ?>" id="maSubShop">
                    <li><a href="users.php" class="nav-link <?= $current_page === 'users.php' ? 'active' : '' ?>"><span>کاربران</span></a></li>
                    <li><a href="products.php" class="nav-link <?= $current_page === 'products.php' ? 'active' : '' ?>"><span>محصولات</span></a></li>
                    <li><a href="categories.php" class="nav-link <?= $current_page === 'categories.php' ? 'active' : '' ?>"><span>دسته‌بندی‌ها</span></a></li>
                    <li><a href="orders.php" class="nav-link <?= $current_page === 'orders.php' ? 'active' : '' ?>"><span>سفارشات</span></a></li>
                </ul>
            </li>

            <li class="nav-heading"><span>سکه و مالی</span></li>
            <li class="nav-item has-submenu <?= $open_money ? 'open' : '' ?>">
                <a class="nav-link <?= $open_money ? '' : 'collapsed' ?>" data-bs-toggle="collapse" href="#maSubMoney" role="button" aria-expanded="<?= $open_money ? 'true' : 'false' ?>">
                    <i class="fas fa-wallet"></i><span>سکه و تراکنش</span><i class="fas fa-chevron-down nav-arrow"></i>
                </a>
                <ul class="nav-submenu collapse <?= $open_money ? 'show' : '' ?>" id="maSubMoney">
                    <li><a href="coin_packages.php" class="nav-link <?= $current_page === 'coin_packages.php' ? 'active' : '' ?>"><span>پکیج‌های سکه</span></a></li>
                    <li><a href="transactions.php" class="nav-link <?= $current_page === 'transactions.php' ? 'active' : '' ?>"><span>تراکنشات</span></a></li>
                    <li><a href="coin_purchases.php" class="nav-link <?= $current_page === 'coin_purchases.php' ? 'active' : '' ?>"><span>خریدهای سکه</span></a></li>
                </ul>
            </li>

            <li class="nav-heading"><span>سرویس‌ها</span></li>
            <li class="nav-item has-submenu <?= $open_int ? 'open' : '' ?>">
                <a class="nav-link <?= $open_int ? '' : 'collapsed' ?>" data-bs-toggle="collapse" href="#maSubInt" role="button" aria-expanded="<?= $open_int ? 'true' : 'false' ?>">
                    <i class="fas fa-plug"></i><span>ارتباطات و API</span><i class="fas fa-chevron-down nav-arrow"></i>
                </a>
                <ul class="nav-submenu collapse <?= $open_int ? 'show' : '' ?>" id="maSubInt">
                    <li><a href="admob.php" class="nav-link <?= $current_page === 'admob.php' ? 'active' : '' ?>"><span>AdMob</span></a></li>
                    <li><a href="telegram_bot.php" class="nav-link <?= $current_page === 'telegram_bot.php' ? 'active' : '' ?>"><span>ربات تلگرام</span></a></li>
                    <li><a href="user_telegram_bot.php" class="nav-link <?= $current_page === 'user_telegram_bot.php' ? 'active' : '' ?>"><span>ربات کاربران</span></a></li>
                    <li><a href="smm_settings.php" class="nav-link <?= $current_page === 'smm_settings.php' ? 'active' : '' ?>"><span>تنظیمات SMM</span></a></li>
                    <li><a href="email_settings.php" class="nav-link <?= $current_page === 'email_settings.php' ? 'active' : '' ?>"><span>تنظیمات ایمیل</span></a></li>
                    <li><a href="email_logs.php" class="nav-link <?= $current_page === 'email_logs.php' ? 'active' : '' ?>"><span>لاگ ایمیل</span></a></li>
                </ul>
            </li>

            <li class="nav-heading"><span>سیستم</span></li>
            <li class="nav-item has-submenu <?= $open_sys ? 'open' : '' ?>">
                <a class="nav-link <?= $open_sys ? '' : 'collapsed' ?>" data-bs-toggle="collapse" href="#maSubSys" role="button" aria-expanded="<?= $open_sys ? 'true' : 'false' ?>">
                    <i class="fas fa-sliders-h"></i><span>تنظیمات و ابزار</span><i class="fas fa-chevron-down nav-arrow"></i>
                </a>
                <ul class="nav-submenu collapse <?= $open_sys ? 'show' : '' ?>" id="maSubSys">
                    <li><a href="settings.php" class="nav-link <?= $current_page === 'settings.php' ? 'active' : '' ?>"><span>تنظیمات اپلیکیشن</span></a></li>
                    <li><a href="reports.php" class="nav-link <?= $current_page === 'reports.php' ? 'active' : '' ?>"><span>گزارش‌ها</span></a></li>
                    <li><a href="backup.php" class="nav-link <?= $current_page === 'backup.php' ? 'active' : '' ?>"><span>پشتیبان‌گیری</span></a></li>
                    <li><a href="versions.php" class="nav-link <?= $current_page === 'versions.php' ? 'active' : '' ?>"><span>نسخه‌های اپ</span></a></li>
                </ul>
            </li>

            <li class="nav-item mt-2 pt-2 ma-nav-logout-wrap">
                <a href="logout.php" class="nav-link ma-nav-logout">
                    <i class="fas fa-sign-out-alt"></i><span>خروج</span>
                </a>
            </li>
        </ul>
    </nav>
</aside>
<div class="sidebar-backdrop" id="adminSidebarBackdrop" aria-hidden="true"></div>
