<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Uni Admin Menu</title>
    <link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap');
        @import url('https://fonts.googleapis.com/css2?family=Tajawal&display=swap');
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Cairo', sans-serif;
            user-select: none;
        }
        
        body {
            background: transparent;
        }
        
        #menu {
            display: none;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 900px;
            height: 550px;
        }
        
        .menu-wrapper {
            width: 100%;
            height: 100%;
            background: rgba(139, 69, 19, 0.98); /* Lighter brown - Saddle Brown */
            border-radius: 15px;
            display: flex;
            position: relative;
            border: 2px solid #DAA520;
            overflow: hidden;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3),
                        0 0 15px rgba(218, 165, 32, 0.3);
            animation: borderGlow 2s ease-in-out infinite;
        }
        
        @keyframes borderGlow {
            0% {
                border-color: #DAA520;
                box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3),
                            0 0 15px rgba(218, 165, 32, 0.3);
            }
            50% {
                border-color: #FFD700;
                box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3),
                            0 0 25px rgba(255, 215, 0, 0.5);
            }
            100% {
                border-color: #DAA520;
                box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3),
                            0 0 15px rgba(218, 165, 32, 0.3);
            }
        }
        
        /* When content is visible, expand the menu */
        
        
        .window-controls {
            position: absolute;
            top: 12px;
            right: 12px;
            display: flex;
            gap: 6px;
            z-index: 10;
        }
        
        .window-btn {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            cursor: pointer;
            transition: all 0.2s ease;
        }
        
        .close-btn { 
            background: #ff5f57;
            box-shadow: 0 0 8px rgba(255, 95, 87, 0.3);
        }
        
        .minimize-btn { 
            background: #febc2e;
            box-shadow: 0 0 8px rgba(254, 188, 46, 0.3);
        }
        
        .maximize-btn { 
            background: rgba(253, 254, 255, 0.3);
            box-shadow: 0 0 8px rgba(253, 254, 255, 0.3);
        }
        
        .window-btn:hover {
            transform: scale(1.1);
            filter: brightness(1.1);
        }
        
        .sidebar {
            width: 260px;
            background: rgba(160, 82, 45, 0.98); /* Lighter brown - Sienna */
            border-right: 1px solid rgba(218, 165, 32, 0.4);
            padding: 20px;
            display: flex;
            flex-direction: column;
        }
        
        .logo {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 15px;
            margin-bottom: 25px;
            background: rgba(144, 143, 160, 0.1);
            border-radius: 10px;
            border: 1px solid rgba(144, 143, 160, 0.2);
        }
        
        .logo i {
            font-size: 28px;
            background: linear-gradient(45deg, #f7f6f5, #b1b1b1);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        .logo-text {
            font-size: 24px;
            font-weight: 700;
            background: linear-gradient(45deg, #f7f6f5, #b1b1b1);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        .nav-section {
            margin-bottom: 20px;
        }
        
        .nav-title {
            color: #6b7280;
            font-size: 12px;
            text-transform: uppercase;
            letter-spacing: 1px;
            padding: 0 12px;
            margin-bottom: 10px;
        }
        
        .nav-item {
            display: flex;
            align-items: center;
            padding: 12px 15px;
            color: #9ca3af;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.3s ease;
            margin: 4px 0;
            border: 1px solid transparent;
        }
        
        .nav-item:hover {
            background: rgba(144, 143, 160, 0.1);
            color: #fff;
            border-color: rgba(144, 143, 160, 0.3);
            transform: translateX(-5px);
        }
        
        .nav-item.active {
            background: rgba(144, 143, 160, 0.15);
            border: 1px solid rgba(144, 143, 160, 0.4);
            color: #fff;
            box-shadow: 0 4px 12px rgba(144, 143, 160, 0.15);
        }
        
        .nav-item i {
            width: 24px;
            margin-left: 12px;
            font-size: 18px;
            color: rgba(253, 254, 255, 0.98);
        }
        
        .content {
            flex: 1;
            padding: 25px;
            overflow-y: auto;
            background: rgba(139, 69, 19, 0.98); /* Matching the menu wrapper */
        }
        
        #players-content, #default-content {
            display: none;
        }
        
        .content-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 25px;
            padding: 0 10px;
        }
        
        .content-title {
            color: #fff;
            font-size: 22px;
            font-weight: 700;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .content-title i {
            color: rgba(253, 254, 255, 0.98);
        }
        
        .search-bar {
            position: relative;
            margin-bottom: 20px;
        }
        
        .search-bar input {
            width: 100%;
            padding: 12px 40px 12px 15px;
            background: rgba(26, 28, 37, 0.7);
            border: 1px solid rgba(144, 143, 160, 0.2);
            border-radius: 8px;
            color: #fff;
            font-size: 14px;
            transition: all 0.3s ease;
        }
        
        .search-bar input:focus {
            outline: none;
            border-color: rgba(253, 254, 255, 0.98);
            box-shadow: 0 0 0 3px rgba(144, 143, 160, 0.2);
        }
        
        .server-status {
            background: rgba(26, 28, 37, 0.7);
            border: 1px solid rgba(144, 143, 160, 0.2);
            border-radius: 10px;
            padding: 15px;
            margin-bottom: 20px;
        }
        
        .status-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .status-header h3 {
            color: #fff;
            font-size: 16px;
            font-weight: 600;
        }
        
        .player-list {
            margin-top: 10px;
            display: grid;
            gap: 12px;
        }
        
        .player-card {
            background: rgba(26, 28, 37, 0.7);
            border: 1px solid rgba(144, 143, 160, 0.2);
            border-radius: 10px;
            padding: 15px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            transition: all 0.3s ease;
        }
        
        .player-card:hover {
            transform: translateX(-5px);
            border-color: rgba(253, 254, 255, 0.98);
            box-shadow: 0 4px 12px rgba(144, 143, 160, 0.15);
        }
        
        .player-info {
            display: flex;
            align-items: center;
            gap: 15px;
        }
        
        .player-avatar {
            width: 40px;
            height: 40px;
            background: linear-gradient(45deg, #5850ec, #4338ca);
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
        }
        
        .player-actions {
            display: flex;
            gap: 8px;
        }
        
        .action-btn {
            padding: 8px 12px;
            border-radius: 6px;
            color: #fff;
            border: 1px solid rgba(144, 143, 160, 0.2);
            background: rgba(19, 21, 29, 0.7);
            cursor: pointer;
            transition: all 0.2s ease;
            display: flex;
            align-items: center;
            gap: 6px;
            font-size: 13px;
        }
        
        .action-btn:hover {
            background: rgba(144, 143, 160, 0.1);
            border-color: rgba(253, 254, 255, 0.98);
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(144, 143, 160, 0.15);
        }
        
        .action-btn.warn:hover {
            border-color: #eab308;
            color: #fcd34d;
        }
        
        .action-btn.danger:hover {
            border-color: #ef4444;
            color: #fca5a5;
        }
        
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 15px;
            margin-bottom: 25px;
        }
        
        .stat-card {
            background: rgba(26, 28, 37, 0.7);
            border: 1px solid rgba(144, 143, 160, 0.2);
            border-radius: 10px;
            padding: 20px;
            transition: all 0.3s ease;
        }
        
        .stat-card:hover {
            transform: translateY(-2px);
            border-color: rgba(253, 254, 255, 0.98);
            box-shadow: 0 4px 12px rgba(144, 143, 160, 0.15);
        }
        
        .stat-value {
            font-size: 24px;
            font-weight: 700;
            color: #fff;
            margin-bottom: 5px;
        }
        
        .stat-label {
            color: #6b7280;
            font-size: 13px;
        }
        
        ::-webkit-scrollbar {
            width: 5px;
        }
        
        ::-webkit-scrollbar-track {
            background: transparent;
        }
        
        ::-webkit-scrollbar-thumb {
            background: rgba(144, 143, 160, 0.3);
            border-radius: 3px;
        }
        
        ::-webkit-scrollbar-thumb:hover {
            background: rgba(144, 143, 160, 0.5);
        }

        .reports-container {
            background: rgba(26, 28, 37, 0.7);
            border: 1px solid rgba(144, 143, 160, 0.2);
            border-radius: 10px;
            padding: 20px;
            height: calc(100vh - 200px);
            max-height: 600px;
            display: flex;
            flex-direction: column;
            gap: 15px;
        }
        
        .reports-controls {
            display: flex;
            gap: 15px;
            align-items: center;
            margin-bottom: 15px;
        }
        
        .logs-list {
            flex: 1;
            overflow-y: auto;
            padding: 10px;
            background: rgba(0, 0, 0, 0.3);
            border-radius: 8px;
            direction: ltr; /* For proper log display */
        }
        
        .log-entry {
            padding: 12px;
            background: rgba(26, 28, 37, 0.7);
            border: 1px solid rgba(144, 143, 160, 0.2);
            border-radius: 6px;
            margin-bottom: 8px;
            color: #fff;
            font-family: 'Courier New', monospace;
            white-space: pre-wrap;
            word-break: break-word;
        }
        
        .log-entry:hover {
            border-color: rgba(253, 254, 255, 0.98);
            transform: translateX(-5px);
            transition: all 0.3s ease;
        }
        
        .log-timestamp {
            color: #6b7280;
            font-size: 0.8em;
            margin-bottom: 5px;
        }
        
        .log-content {
            color: #e5e7eb;
        }
        
        .log-entry.warning {
            border-left: 3px solid #fbbf24;
        }
        
        .log-entry.error {
            border-left: 3px solid #ef4444;
        }
        
        .log-entry.info {
            border-left: 3px solid #3b82f6;
        }
    </style>
    
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Cairo', sans-serif;
            user-select: none;
        }
    
        body {
            background: transparent;
        }
    
        #menu {
            display: none;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 900px;
            height: 550px;
        }
    
        .menu-wrapper {
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.95) !important;  /* Using !important to override */
            border-radius: 15px;
            display: flex;
            position: relative;
            border: 2px solid rgba(253, 254, 255, 0.3);;
            overflow: hidden;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3),
                        0 0 15px rgba(253, 254, 255, 0.3);
        }
    
        .sidebar {
            width: 260px;
            background: rgba(0, 0, 0, 0.95) !important;  /* Using !important to override */
            border-right: 1px solid rgba(253, 254, 255, 0.2);
            padding: 20px;
            display: flex;
            flex-direction: column;
        }
    
        .content {
            flex: 1;
            padding: 25px;
            overflow-y: auto;
            background: rgba(0, 0, 0, 0.95) !important;  /* Using !important to override */
        }
    
        /* Add glowing green border animation */
        @keyframes borderGlow {
            0% {
                border-color: rgba(253, 254, 255, 0.3);;
                box-shadow: 0 0 15px rgba(253, 254, 255, 0.3);
            }
            50% {
                border-color: rgba(253, 254, 255, 0.3);;
                box-shadow: 0 0 25px rgba(253, 254, 255, 0.5);
            }
            100% {
                border-color: rgba(253, 254, 255, 0.3);;
                box-shadow: 0 0 15px rgba(253, 254, 255, 0.3);
            }
        }
    
        .menu-wrapper {
            animation: borderGlow 2s ease-in-out infinite;
        }
    </style>
</head>
<body>

    <div id="menu">
        <div class="menu-wrapper">
            <div class="window-controls">
                <div class="window-btn close-btn" onclick="closeMenu()"></div>
                <div class="window-btn minimize-btn"></div>
                <div class="window-btn maximize-btn"></div>
            </div>

            <div class="sidebar">
                <div class="logo">
                    <i class="fas fa-shield-alt"></i>
                    <span class="logo-text">Uni AntiCheat</span>
                </div>

                <div class="nav-section">
                    <div class="nav-title">نظرة عامة</div>
                    <div class="nav-item active" onclick="showSection('dashboard')">
                        <i class="fas fa-home"></i>
                        لوحة التحكم
                    </div>
                    <div class="nav-item" onclick="showSection('players')">
                        <i class="fas fa-users"></i>
                        اللاعبين
                    </div>
                </div>

                <div class="nav-section">
                    <div class="nav-title">الحماية</div>
                    <div class="nav-item" onclick="showSection('security')">
                        <i class="fas fa-shield-alt"></i>
                        إعدادات الحماية
                    </div>
                    <div class="nav-item" onclick="showSection('banned')">
                        <i class="fas fa-user-slash"></i>
                        قائمة الحظر
                    </div>
                    <div class="nav-item" onclick="showSection('reports')">
                        <i class="fas fa-flag"></i>
                        البلاغات
                    </div>
                </div>

                <div class="nav-section">
                    <div class="nav-title">الإدارة</div>
                    <div class="nav-item" onclick="showSection('admins')">
                        <i class="fas fa-user-shield"></i>
                        المشرفين
                    </div>
                    <div class="nav-item" onclick="showSection('logs')">
                        <i class="fas fa-history"></i>
                        السجلات
                    </div>
                </div>
            </div>

            <div class="content">
                <div id="default-content">
                    <div class="content-header">
                        <h2 class="content-title">
                            <i class="fas fa-home"></i>
                            لوحة التحكم
                        </h2>
                    </div>

                    <div class="stats-grid">
                        <div class="stat-card">
                            <div class="stat-value" id="players-count">0</div>
                            <div class="stat-label">اللاعبين النشطين</div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-value" id="warnings-count">0</div>
                            <div class="stat-label">التحذيرات</div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-value" id="bans-count">0</div>
                            <div class="stat-label">عمليات الحظر</div>
                        </div>
                    </div>

                    <div class="stat-card action-card">
                        <button class="custom-btn freecam-btn" onclick="toggleFreeCam()">
                            <i class="fas fa-video"></i>
                            كاميرا حرة
                        </button>
                        <div class="feature-desc">الانتقال إلى وضع الكاميرا الحرة</div>
                    </div>
                    <div id="freecam-overlay" style="display: none;">
                        <!-- Crosshair -->
                        <div class="crosshair">+</div>
                        
                        <!-- Info panel -->
                        <div class="info-box">
                            <span class="info-text"></span>
                            <div class="tooltip">Click to copy</div>
                        </div>
                    </div>
                </div>

                <div id="players-content" style="display: none;">
                    <div class="content-header">
                        <h2 class="content-title">
                            <i class="fas fa-users"></i>
                            اللاعبين النشطين
                        </h2>
                    </div>

                    <div class="search-bar">
                        <input type="text" placeholder="البحث عن لاعب...">
                        <i class="fas fa-search"></i>
                    </div>

                    <div class="server-status">
                        <div class="status-header">
                            <h3>اللاعبين في السيرفر: <span id="online-count">0</span></h3>
                        </div>
                    </div>

                    <div id="player-list" class="player-list">
                        <!-- Players will be inserted here -->
                    </div>
                </div>
                <div id="reports-content" style="display: none;">
                    <div class="content-header">
                        <h2 class="content-title">
                            <i class="fas fa-flag"></i>
                            البلاغات والسجلات
                        </h2>
                        <div class="search-bar">
                            <input type="text" placeholder="البحث في السجلات..." dir="rtl">
                        </div>
                        <button class="action-btn refresh-btn" onclick="refreshLogs()">
                            <i class="fas fa-sync-alt"></i>
                            تحديث السجلات
                        </button>
                    </div>
                
                    <div class="reports-container">
                        <div class="logs-list" id="logs-list">
                            <!-- Logs will be inserted here -->
                        </div>
                    </div>
                </div>
        </div>
    </div>

    <style>
        .action-card {
            display: flex;
            flex-direction: column;
            gap: 10px;
            align-items: center;
            justify-content: center;
            text-align: center;
        }
        
        .custom-btn {
            width: 100%;
            padding: 12px;
            border-radius: 8px;
            background: rgba(255, 255, 255, 0.05);
            border: 1px solid rgba(255, 255, 255, 0.1);
            color: #fff;
            font-size: 14px;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            font-family: 'Cairo', sans-serif;
        }
        
        .custom-btn:hover {
            background: rgba(255, 255, 255, 0.1);
            border-color: rgba(255, 255, 255, 0.2);
            transform: translateY(-2px);
        }
        
        .custom-btn i {
            font-size: 16px;
        }
        
        .freecam-btn {
            background: rgba(59, 130, 246, 0.1);
            border-color: rgba(59, 130, 246, 0.2);
        }
        
        .freecam-btn:hover {
            background: rgba(59, 130, 246, 0.2);
            border-color: rgba(59, 130, 246, 0.3);
        }
        
        .feature-desc {
            color: #6b7280;
            font-size: 12px;
        }

        #freecam-overlay {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
            z-index: 1000;
        }

        .crosshair {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: rgba(255, 255, 255, 0.8);
            font-size: 24px;
            text-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
            font-family: Arial, sans-serif;
        }

        .info-panel {
            position: absolute;
            bottom: 50px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0, 0, 0, 0.8);
            border: 1px solid rgba(255, 255, 255, 0.1);
            border-radius: 8px;
            padding: 15px;
            min-width: 300px;
            color: white;
            font-family: 'Cairo', sans-serif;
            pointer-events: all;
            display: none;
        }

        .info-content {
            margin-bottom: 10px;
            font-size: 14px;
            line-height: 1.4;
        }

        .copy-btn {
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.2);
            color: white;
            padding: 8px 15px;
            border-radius: 4px;
            cursor: pointer;
            font-family: 'Cairo', sans-serif;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 8px;
            font-size: 13px;
        }

        .copy-btn:hover {
            background: rgba(255, 255, 255, 0.2);
            border-color: rgba(255, 255, 255, 0.3);
        }
</style>

<style>
    #freecam-overlay {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        pointer-events: none;
        z-index: 1000;
    }
    
    .crosshair {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        color: rgba(255, 255, 255, 0.8);
        font-size: 24px;
        text-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
        font-family: Arial, sans-serif;
    }
    
    .info-box {
        position: absolute;
        bottom: 50px;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(0, 0, 0, 0.7);
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 4px;
        padding: 8px 12px;
        color: white;
        font-family: 'Cairo', sans-serif;
        font-size: 14px;
        pointer-events: all;
        cursor: pointer;
        display: none;
        transition: all 0.2s ease;
    }
    
    .info-box:hover {
        background: rgba(0, 0, 0, 0.8);
        transform: translateX(-50%) translateY(-2px);
    }
    
    .tooltip {
        position: absolute;
        top: -25px;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(0, 0, 0, 0.8);
        padding: 4px 8px;
        border-radius: 4px;
        font-size: 12px;
        opacity: 0;
        transition: opacity 0.2s ease;
    }
    
    .info-box:hover .tooltip {
        opacity: 1;
    }
    
    .copied {
        background: rgba(16, 185, 129, 0.7) !important;
        border-color: rgba(16, 185, 129, 0.3);
    }
    </style>


        <script>
            let lastInfo = '';
            let freecamActive = false;
            
            function showFreecamOverlay(show) {
                document.getElementById('freecam-overlay').style.display = show ? 'block' : 'none';
            }
            
            function updateInfoBox(info) {
                const infoBox = document.querySelector('.info-box');
                const infoText = document.querySelector('.info-text');
                
                if (info) {
                    lastInfo = info;
                    infoText.textContent = info;
                    infoBox.style.display = 'block';
                } else {
                    infoBox.style.display = 'none';
                }
            }
            
            // Make the info box clickable
            document.querySelector('.info-box').addEventListener('click', function() {
                if (lastInfo) {
                    navigator.clipboard.writeText(lastInfo);
                    this.classList.add('copied');
                    setTimeout(() => {
                        this.classList.remove('copied');
                    }, 1000);
                }
            });
            
            // Update existing toggleFreeCam function
            function toggleFreeCam() {
                freecamActive = !freecamActive;
                const btn = document.querySelector('.freecam-btn');
                if (freecamActive) {
                    btn.style.background = 'rgba(59, 130, 246, 0.2)';
                    btn.style.borderColor = 'rgba(59, 130, 246, 0.3)';
                    showFreecamOverlay(true);
                    // Close menu when activating FreeCam
                    closeMenu();
                } else {
                    btn.style.background = 'rgba(59, 130, 246, 0.1)';
                    btn.style.borderColor = 'rgba(59, 130, 246, 0.2)';
                    showFreecamOverlay(false);
                }
                
                $.post(`https://${GetParentResourceName()}/toggleFreeCam`, JSON.stringify({}));
            }
            
            // Update the message handler
            window.addEventListener('message', function(event) {
                if (event.data.type === 'updateFreecamInfo') {
                    updateInfoBox(event.data.info);
                }
            });
            </script>

    <script>
        let activePlayers = [];
        let currentSection = 'dashboard';

        function showSection(sectionId) {
            $('.nav-item').removeClass('active');
            $(event.currentTarget).addClass('active');
            currentSection = sectionId;

            // Hide all content sections
            $('#default-content, #players-content').hide();

            // Show the selected section
            if (sectionId === 'players') {
                $('#players-content').show();
                fetchPlayers();
            } else if (sectionId === 'dashboard') {
                $('#default-content').show();
            }

            // Update title and icon
            const titles = {
                'dashboard': 'لوحة التحكم',
                'players': 'اللاعبين النشطين',
                'security': 'إعدادات الحماية',
                'banned': 'قائمة الحظر',
                'reports': 'البلاغات',
                'admins': 'المشرفين',
                'logs': 'السجلات'
            };

            const icons = {
                'dashboard': 'home',
                'players': 'users',
                'security': 'shield-alt',
                'banned': 'user-slash',
                'reports': 'flag',
                'admins': 'user-shield',
                'logs': 'history'
            };

            $('.content-title').html(`
                <i class="fas fa-${icons[sectionId]}"></i>
                ${titles[sectionId]}
            `);
        }

        function fetchPlayers() {
            $.post(`https://${GetParentResourceName()}/getPlayerData`, JSON.stringify({}))
                .done(function(players) {
                    console.log("Received players:", players); // Debug log
                    if (Array.isArray(players)) {
                        activePlayers = players;
                        updatePlayerList(players);
                        $('#players-count').text(players.length);
                        $('#online-count').text(players.length);
                    } else {
                        console.error("Invalid players data received");
                    }
                })
                .fail(function(err) {
                    console.error("Error fetching players:", err);
                });
        }

        function updatePlayerList(players) {
            const playerList = $('#player-list');
            playerList.empty();

            // Update online count
            $('#online-count').text(players.length);
            $('#players-count').text(players.length);

            if (players.length === 0) {
                playerList.append(`
                    <div class="player-card">
                        <div class="player-info">
                            <div class="player-details">
                                <h3 style="color: #6b7280; font-size: 15px;">
                                    لا يوجد لاعبين نشطين
                                </h3>
                            </div>
                        </div>
                    </div>
                `);
                return;
            }

            players.forEach(player => {
                playerList.append(`
                    <div class="player-card">
                        <div class="player-info">
                            <div class="player-avatar">
                                <i class="fas fa-user"></i>
                            </div>
                            <div class="player-details">
                                <h3 style="color: #fff; font-size: 15px; margin-bottom: 4px;">
                                    ${player.name}
                                </h3>
                                <div style="color: #6b7280; font-size: 13px;">
                                    <i class="fas fa-id-card"></i> ID: ${player.id}
                                </div>
                            </div>
                        </div>
                        <div class="player-actions">
                            <button class="action-btn" onclick="spectatePlayer('${player.id}')">
                                <i class="fas fa-eye"></i>
                                مراقبة
                            </button>
                            <button class="action-btn" onclick="teleportPlayer('${player.id}')">
                                <i class="fas fa-map-marker-alt"></i>
                                انتقال
                            </button>
                            <button class="action-btn warn" onclick="warnPlayer('${player.id}')">
                                <i class="fas fa-exclamation-triangle"></i>
                                تحذير
                            </button>
                            <button class="action-btn danger" onclick="kickPlayer('${player.id}')">
                                <i class="fas fa-user-slash"></i>
                                طرد
                            </button>
                            <button class="action-btn danger" onclick="banPlayer('${player.id}')">
                                <i class="fas fa-ban"></i>
                                حظر
                            </button>
                        </div>
                    </div>
                `);
            });
        }

        function spectatePlayer(id) {
            $.post(`https://${GetParentResourceName()}/spectatePlayer`, JSON.stringify({
                playerId: id
            }));
        }

        function teleportPlayer(id) {
            $.post(`https://${GetParentResourceName()}/teleportPlayer`, JSON.stringify({
                playerId: id
            }));
        }

        function warnPlayer(id) {
            const reason = prompt('سبب التحذير:');
            if (reason) {
                $.post(`https://${GetParentResourceName()}/warnPlayer`, JSON.stringify({
                    playerId: id,
                    reason: reason
                }));
            }
        }

        function kickPlayer(id) {
            const reason = prompt('سبب الطرد:');
            if (reason) {
                $.post(`https://${GetParentResourceName()}/kickPlayer`, JSON.stringify({
                    playerId: id,
                    reason: reason
                }));
            }
        }

        function banPlayer(id) {
            const reason = prompt('سبب الحظر:');
            const duration = prompt('مدة الحظر (بالأيام):');
            if (reason && duration) {
                $.post(`https://${GetParentResourceName()}/banPlayer`, JSON.stringify({
                    playerId: id,
                    reason: reason,
                    duration: parseInt(duration)
                }));
            }
        }

        function closeMenu() {
            $("#menu").fadeOut(300);
            $.post(`https://${GetParentResourceName()}/closeMenu`, JSON.stringify({}));
        }

        // Initialize
        $(document).ready(function() {
            // Message handler
            window.addEventListener('message', function(event) {
                if (event.data.action === 'open') {
                    $("#menu").fadeIn(300);
                    if (currentSection === 'players') {
                        fetchPlayers();
                    }
                }
            });

            // Search functionality
            $('.search-bar input').on('input', function() {
                const searchTerm = $(this).val().toLowerCase();
                if (activePlayers.length) {
                    const filteredPlayers = activePlayers.filter(player => 
                        player.name.toLowerCase().includes(searchTerm) || 
                        player.id.toString().includes(searchTerm)
                    );
                    updatePlayerList(filteredPlayers);
                }
            });

            // Close menu on ESC
            $(document).keyup(function(e) {
                if (e.key === "Escape") {
                    closeMenu();
                }
            });

            // Refresh players list periodically when the menu is open
            setInterval(() => {
                if ($("#menu").is(":visible") && currentSection === 'players') {
                    fetchPlayers();
                }
            }, 5000);
        });
    </script>
    <script>


        // Add to your existing showSection function
        function showSection(sectionId) {
            $('.nav-item').removeClass('active');
            $(event.currentTarget).addClass('active');
            currentSection = sectionId;
        
            // Hide all content sections
            $('#default-content, #players-content, #reports-content').hide();
        
            // Show the selected section
            if (sectionId === 'players') {
                $('#players-content').show();
                fetchPlayers();
            } else if (sectionId === 'dashboard') {
                $('#default-content').show();
            } else if (sectionId === 'reports') {
                $('#reports-content').show();
                fetchLogs();
            }
        }
        
        function fetchLogs() {
            $.post(`https://${GetParentResourceName()}/fetchLogs`, JSON.stringify({}));
        }
        
        function refreshLogs() {
            fetchLogs();
        }
        
        function formatLogEntry(log) {
            // Remove asterisks from reason
            const cleanReason = log.reason.replace(/\*\*/g, '');
            
            return `
                <div class="log-entry">
                    <div class="log-line id">ID: ${log.id}</div>
                    <div class="log-line ip">${log.ip}</div>
                    <div class="log-line reason">${cleanReason}</div>
                    <div class="log-line license">${log.license}</div>
                </div>
            `;
        }

        // Add to your existing message handler
        window.addEventListener('message', function(event) {
            if (event.data.action === 'updateLogs') {
                const logsList = $('#logs-list');
                logsList.empty();
                
                if (Array.isArray(event.data.logs)) {
                    event.data.logs.forEach(log => {
                        logsList.append(formatLogEntry(log));
                    });
                }
            }
        });
        
        // Add search functionality for logs
        $('.search-bar input').on('input', function() {
            const searchTerm = $(this).val().toLowerCase();
            $('.log-entry').each(function() {
                const logText = $(this).text().toLowerCase();
                $(this).toggle(logText.includes(searchTerm));
            });
        });
        </script>



        
</body>
</html>