<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $title ?></title>
    <link rel="stylesheet" href="/css/admin.css">
</head>
<body class="admin-page">
    <div class="admin-header">
        <h1>Redis-Informationen</h1>
    </div>

    <div class="admin-nav">
        <a href="/admin">Dashboard</a>
        <a href="/admin/routes">Routen</a>
        <a href="/admin/services">Dienste</a>
        <a href="/admin/environment">Umgebung</a>
        <a href="/admin/performance">Performance</a>
        <a href="/admin/redis" class="active">Redis</a>
        <a href="/admin/phpinfo">PHP Info</a>
    </div>

    <div class="admin-content">
        <?php if (isset($redis['status']) && $redis['status'] === 'Verbunden'): ?>
            <div class="dashboard-stats">
                <div class="stat-box">
                    <h3>Status</h3>
                    <div class="stat-value status-connected"><?= $redis['status'] ?></div>
                </div>

                <div class="stat-box">
                    <h3>Version</h3>
                    <div class="stat-value"><?= $redis['version'] ?></div>
                </div>

                <div class="stat-box">
                    <h3>Uptime</h3>
                    <div class="stat-value"><?= $redis['uptime'] ?></div>
                </div>

                <div class="stat-box">
                    <h3>Speicherverbrauch</h3>
                    <div class="stat-value"><?= $redis['memory'] ?></div>
                </div>

                <div class="stat-box">
                    <h3>Max. Speicherverbrauch</h3>
                    <div class="stat-value"><?= $redis['peak_memory'] ?></div>
                </div>

                <div class="stat-box">
                    <h3>Verbundene Clients</h3>
                    <div class="stat-value"><?= $redis['clients'] ?></div>
                </div>

                <div class="stat-box">
                    <h3>Anzahl Schlüssel</h3>
                    <div class="stat-value"><?= $redis['keys'] ?></div>
                </div>
            </div>

            <div class="admin-section">
                <h2>Schlüssel (max. 50 angezeigt)</h2>
                <div class="admin-tools">
                    <input type="text" id="keyFilter" placeholder="Schlüssel filtern..." class="search-input">
                </div>

                <div class="key-list" id="keyList">
                    <?php if (empty($redis['key_sample'])): ?>
                        <div class="empty-message">Keine Schlüssel vorhanden</div>
                    <?php else: ?>
                        <?php foreach($redis['key_sample'] as $key): ?>
                        <div class="key-item">
                            <?= $key ?>
                        </div>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </div>
            </div>
        <?php else: ?>
            <div class="error-message">
                <h2>Redis-Verbindung fehlgeschlagen</h2>
                <p><?= $redis['status'] ?? 'Unbekannter Fehler' ?></p>
            </div>
        <?php endif; ?>
    </div>

    <div class="admin-footer">
        <p>&copy; <?= date('Y') ?> Framework Admin</p>
    </div>

    <script>
        document.getElementById('keyFilter')?.addEventListener('input', function() {
            const filterValue = this.value.toLowerCase();
            const items = document.querySelectorAll('#keyList .key-item');

            items.forEach(item => {
                const text = item.textContent.toLowerCase();
                item.style.display = text.includes(filterValue) ? '' : 'none';
            });
        });
    </script>
</body>
</html>
