{% extends "base.html" %}
{% block title %}Game List — Admin — {{ config.BBS_NAME }}{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-3">
    <h3><i class="bi bi-list"></i> Games</h3>
    <div class="d-flex gap-2">
        <a href="{{ url_for('games_admin.add_game') }}" class="btn btn-primary btn-sm">
            <i class="bi bi-plus-circle"></i> Add Game
        </a>
        <a href="{{ url_for('games_admin.dashboard') }}" class="btn btn-primary btn-sm">
            <i class="bi bi-arrow-left"></i> Dashboard
        </a>
    </div>
</div>

<table class="table table-striped">
    <thead>
        <tr>
            <th>Name</th>
            <th>Type</th>
            <th>Category</th>
            <th>Plays</th>
            <th>Status</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
        {% for game in games %}
        <tr>
            <td>
                <i class="bi {{ game.icon or 'bi-controller' }}"></i>
                {{ game.name }}
            </td>
            <td><small>{{ game.game_type }}</small></td>
            <td>{{ game.category | capitalize }}</td>
            <td>{{ game.play_count or 0 }}</td>
            <td>
                <span class="badge"
                      style="background:{% if game.is_active %}#003300{% else %}#330000{% endif %};color:{% if game.is_active %}#00ff00{% else %}#ff0000{% endif %};">
                    {% if game.is_active %}Active{% else %}Inactive{% endif %}
                </span>
            </td>
            <td>
                <a href="{{ url_for('games.detail', slug=game.slug) }}"
                   class="btn btn-sm btn-primary" title="View">
                    <i class="bi bi-eye"></i>
                </a>
                <a href="{{ url_for('games_admin.edit_game', game_id=game.id) }}"
                   class="btn btn-sm btn-primary" title="Edit">
                    <i class="bi bi-pencil"></i>
                </a>
                <form method="post"
                      action="{{ url_for('games_admin.delete_game', game_id=game.id) }}"
                      style="display:inline;"
                      onsubmit="return confirm('Delete {{ game.name }}?');">
        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                    <button type="submit" class="btn btn-sm"
                            style="background:#330000;border:1px solid #ff0000;color:#ff0000;"
                            title="Delete">
                        <i class="bi bi-trash"></i>
                    </button>
                </form>
            </td>
        </tr>
        {% else %}
        <tr><td colspan="6" class="text-center" style="color:#007700;">No games yet.</td></tr>
        {% endfor %}
    </tbody>
</table>
{% endblock %}
