<?php require_once __DIR__ . '/../config.php'; ?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo SITE_NAME; ?></title>
    <link rel="icon" type="image/x-icon" href="<?php echo $logoPath; ?>">
    <!-- Bootstrap RTL CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.rtl.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <!-- Custom CSS -->
    <link rel="stylesheet" href="<?php echo SITE_URL; ?>/assets/css/style.css">
  
</head>
<body>
    <!-- Navbar -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary sticky-top">
        <div class="container">
            <a class="navbar-brand" href="<?php echo SITE_URL; ?>">
                <?php 
                $settings = getAssociationSettings();
                $logoPath = !empty($settings['logo']) ? SITE_URL . '/uploads/logo/' . $settings['logo'] : SITE_URL . '/assets/img/default-logo.png';
                ?>
                <img src="<?php echo $logoPath; ?>" alt="شعار" height="40" class="me-2">
                <?php echo $settings['name'] ?? SITE_NAME; ?>
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            
            <?php if (isLoggedIn()): ?>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                    <li class="nav-item">
                        <a class="nav-link" href="<?php echo SITE_URL; ?>/index.php"><i class="fas fa-home"></i> الرئيسية</a>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="membersDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                            <i class="fas fa-users"></i> المنخرطين
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="membersDropdown">
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/members/index.php">قائمة المنخرطين</a></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/members/add.php">إضافة منخرط جديد</a></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/members/subscriptions.php">الاشتراكات</a></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/members/notifications.php">إشعارات الاشتراكات</a></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/members/cards.php">بطاقات العضوية</a></li>
                        </ul>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="coachesDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                            <i class="fas fa-user-tie"></i> المؤطرين
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="coachesDropdown">
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/coaches/index.php">قائمة المؤطرين</a></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/coaches/add.php">إضافة مؤطر جديد</a></li>
                        </ul>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="trainingDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                            <i class="fas fa-calendar-alt me-1"></i> التدريب
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="trainingDropdown">
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/training/sessions.php">حصص التدريب</a></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/training/sessions.php">سجل الحضور</a></li>
                        </ul>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="eventsDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                            <i class="fas fa-trophy"></i> الأنشطة
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="eventsDropdown">
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/events/index.php">قائمة الأنشطة</a></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/events/add.php">إضافة نشاط جديد</a></li>
                        </ul>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="financeDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                            <i class="fas fa-money-bill-wave"></i> المالية
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="financeDropdown">
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/finance/index.php">لوحة المعلومات المالية</a></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/finance/income/index.php">المداخيل</a></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/finance/expenses/index.php">المصاريف</a></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/finance/stats.php">الإحصائيات المالية</a></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/finance/reports.php">التقارير المالية</a></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/reports/global_report.php">التقرير الإجمالي</a></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/finance/settings.php">الإعدادات المالية</a></li>
                        </ul>
                    </li>
                    <?php if (hasPermission('admin')): ?>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="settingsDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                            <i class="fas fa-cog"></i> الإعدادات
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="settingsDropdown">
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/settings/categories.php">الفئات</a></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/settings/category_fees.php">رسوم الفئات</a></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/settings/users.php">المستخدمين</a></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/settings/association.php">إعدادات الجمعية</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/settings/import_export.php"><i class="fas fa-exchange-alt"></i> استيراد وتصدير البيانات</a></li>
                        </ul>
                    </li>
                    <?php endif; ?>
                </ul>
                <div class="d-flex">
                    <div class="dropdown">
                        <button class="btn btn-outline-light dropdown-toggle" type="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
                            <i class="fas fa-user-circle"></i> <?php echo $_SESSION['user_name']; ?>
                        </button>
                        <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/profile.php"><i class="fas fa-id-card"></i> الملف الشخصي</a></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/change-password.php"><i class="fas fa-key"></i> تغيير كلمة المرور</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="<?php echo SITE_URL; ?>/logout.php"><i class="fas fa-sign-out-alt"></i> تسجيل الخروج</a></li>
                        </ul>
                    </div>
                </div>
            </div>
            <?php endif; ?>
        </div>
    </nav>
    
    <!-- Main Content -->
    <div class="container mt-4">
        <?php displayAlert(); ?>
