{% extends "explorer/base.html" %}
{% load i18n %}

{% block sql_explorer_content %}
    <h3>{% blocktrans with pagenum=page_obj.number %}Recent Query Logs - Page {{pagenum}}{% endblocktrans %}</h3>
    <div class="table-responsive">
        <table class="table table-striped query-list">
            <thead>
                <tr>
                    <th>{% trans "Run At" %}</th>
                    <th>{% trans "Run By" %}</th>
                    <th>{% trans "Duration" %}</th>
                    <th class="sql">SQL</th>
                    <th>{% trans "Query ID" %}</th>
                    <th>{% trans "Playground" %}</th>
                </tr>
            </thead>
            <tbody>
                {% for object in recent_logs %}
                    <tr>
                        <td>{{ object.run_at|date:"SHORT_DATETIME_FORMAT" }}</td>
                        <td>{{ object.run_by_user.email }}</td>
                        <td>{{ object.duration|floatformat:2 }}ms</td>
                        <td class="log-sql">{{ object.sql }}</td>
                        <td>
                            {% if object.query_id %}
                                <a href="{% url "query_detail" object.query_id %}">
                                    {% blocktrans trimmed with query_id=object.query_id %}
                                        Query {{ query_id }}
                                    {% endblocktrans %}
                                </a>
                            {% elif object.is_playground %}
                                {% trans "Playground" %}
                            {% else %}
                                --
                            {% endif %}
                        </td>
                        <td>
                            <a href="{% url "explorer_playground" %}?querylog_id={{ object.id }}">
                                {% trans "Open" %}
                            </a>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
    {% if is_paginated %}
        <div class="pagination">
            <span class="page-links">
                {% if page_obj.has_previous %}
                    <a href="?page={{ page_obj.previous_page_number }}"><<</a>
                {% endif %}
                <span class="page-current">
                    {% blocktrans trimmed with pnum=page_obj.number anum=page_obj.paginator.num_pages %}
                        Page {{ pnum }} of {{ anum }}.
                    {% endblocktrans %}
                </span>
                {% if page_obj.has_next %}
                    <a href="?page={{ page_obj.next_page_number }}">>></a>
                {% endif %}
            </span>
        </div>
    {% endif %}
{% endblock %}
