{% extends 'base.html.twig' %}

{% block title %}Game Admin Dashboard{% endblock %}

{% block body %}
    <h1>Game Admin Dashboard</h1>

    <div style="display: flex; gap: 2rem;">
        <div style="flex: 1;">
            <h2>All Players ({{ players|length }})</h2>
            <table style="width: 100%; border-collapse: collapse;">
                <thead>
                    <tr style="background-color: #f2f2f2;">
                        <th>ID</th>
                        <th>Username</th>
                        <th>Email</th>
                        <th>Roles</th>
                        <th>Verified</th>
                    </tr>
                </thead>
                <tbody>
                    {% for player in players %}
                        <tr>
                            <td>{{ player.id }}</td>
                            <td>{{ player.username }}</td>
                            <td>{{ player.email }}</td>
                            <td>{{ player.roles|join(', ') }}</td>
                            <td>{{ player.isVerified ? 'Yes' : 'No' }}</td>
                        </tr>
                    {% else %}
                        <tr>
                            <td colspan="5">No players found.</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

        <div style="flex: 2;">
            <h2>All Sessions ({{ sessions|length }})</h2>
            <table style="width: 100%; border-collapse: collapse;">
                <thead>
                    <tr style="background-color: #f2f2f2;">
                        <th>ID</th>
                        <th>Game</th>
                        <th>Status</th>
                        <th>Players Joined</th>
                        <th>Created At</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    {% for session in sessions %}
                        <tr>
                            <td>{{ session.id }}</td>
                            <td>{{ session.game.name }}</td>
                            <td>{{ session.status.value }}</td>
                            <td>
                                <ul>
                                    {% for p in session.players %}
                                        <li>{{ p.user.username }} (Screen: {{ p.screen ?? 'N/A' }})</li>
                                    {% else %}
                                        <li>No players</li>
                                    {% endfor %}
                                </ul>
                                ({{ session.players|length }} / {{ session.game.numberOfPlayers }})
                            </td>
                            <td>{{ session.created|date('Y-m-d H:i') }}</td>
                            <td>
                                <a href="{{ path('game_admin_view_session', {session: session.id}) }}">View Game Logs</a>
                            </td>
                        </tr>
                    {% else %}
                        <tr>
                            <td colspan="6">No sessions found.</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}
