{% extends "admin/dj_redis_panel/base.html" %}
{% load i18n admin_urls static %}

{% block breadcrumbs %}
<div class="breadcrumbs">
    <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
    &rsaquo; <a href="{% url 'dj_redis_panel:index' %}">{% trans 'Redis Instances' %}</a>
    &rsaquo; {{ instance_alias }}
</div>
{% endblock %}

{% block content %}
<div class="module">
    <!-- Instance Information -->
    <div class="module">
        <h2>{% trans 'System Information' %}</h2>
        {% if error_message %}
        <div class="errors">
            <p><strong>{% trans 'Connection Error:' %}</strong> {{ error_message }}</p>
        </div>
        {% elif hero_numbers %}
        <div class="instance-stats">
            <div class="stats-grid">
                <div class="stat-item">
                    <strong>{% trans 'Redis Version' %}</strong><br>
                    <span class="stat-value">{{ hero_numbers.version }}</span>
                </div>
                <div class="stat-item">
                    <strong>{% trans 'Memory Used' %}</strong><br>
                    <span class="stat-value">{{ hero_numbers.memory_used }}</span>
                </div>
                <div class="stat-item">
                    <strong>{% trans 'Peak Memory' %}</strong><br>
                    <span class="stat-value">{{ hero_numbers.memory_peak }}</span>
                </div>
                <div class="stat-item">
                    <strong>{% trans 'Connected Clients' %}</strong><br>
                    <span class="stat-value">{{ hero_numbers.connected_clients }}</span>
                </div>
                <div class="stat-item">
                    <strong>{% trans 'Uptime' %}</strong><br>
                    <span class="stat-value">{{ hero_numbers.uptime|floatformat:0 }}s</span>
                </div>
                <div class="stat-item">
                    <strong>{% trans 'Commands Processed' %}</strong><br>
                    <span class="stat-value">{{ hero_numbers.total_commands_processed|floatformat:0 }}</span>
                </div>
            </div>
        </div>
        {% endif %}
    </div>

    <!-- Databases Overview -->
    {% if databases and not error_message %}

    <div class="module">
        <h2>{% trans 'Databases' %}</h2>
        <br>
        <div class="results">
            <table id="result_list">
                <thead>
                    <tr>
                        <th scope="col">{% trans 'DB Name' %}</th>
                        <th scope="col">{% trans 'Keys' %}</th>
                        <th scope="col">{% trans 'Avg TTL (s)' %}</th>
                        <th scope="col">{% trans 'Expires' %}</th>
                        <th scope="col">{% trans 'Actions' %}</th>
                    </tr>
                </thead>
                <tbody>
                    {% for db in databases %}
                    <tr class="{% cycle 'row1' 'row2' %}">
                        <td>
                            <strong>DB {{ db.db_number }}</strong>
                            {% if db.is_default %}
                                <span class="default-badge">{% trans 'default' %}</span>
                            {% endif %}
                        </td>
                        <td>
                            {% if db.keys > 0 %}
                                <strong>{{ db.keys|floatformat:0 }}</strong>
                            {% else %}
                                <span class="quiet">{% trans 'Empty' %}</span>
                            {% endif %}
                        </td>
                        <td>
                            {% if db.avg_ttl > 0 %}
                                <span>{{ db.avg_ttl|floatformat:0 }}s</span>
                            {% else %}
                                <span class="quiet">—</span>
                            {% endif %}
                        </td>
                        <td>
                            {% if db.expires > 0 %}
                                {{ db.expires|floatformat:0 }}
                            {% else %}
                                <span class="quiet">—</span>
                            {% endif %}
                        </td>
                        <td>
                            {% if db.keys > 0 %}
                                <a href="{% url 'dj_redis_panel:key_search' instance_alias db.db_number %}" class="default">
                                    {% trans 'Browse Keys' %}
                                </a>
                            {% else %}
                                <span class="quiet">{% trans 'No keys' %}</span>
                            {% endif %}
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>

    {% endif %}

</div>
{% endblock %}
