{% load i18n l10n %}
<ul>
  {% for alias, info in databases %}
    <li>
      <strong><span class="djdt-color" data-djdt-styles="backgroundColor:rgb({{ info.rgb_color|join:', ' }})"></span> {{ alias }}</strong>
      {{ info.time_spent|floatformat:"2" }} ms ({% blocktrans count info.num_queries as num %}{{ num }} query{% plural %}{{ num }} queries{% endblocktrans %}
      {% if info.similar_count %}
        {% blocktrans with count=info.similar_count trimmed %}
          including <abbr title="Similar queries are queries with the same SQL, but potentially different parameters.">{{ count }} similar</abbr>
        {% endblocktrans %}
        {% if info.duplicate_count %}
          {% blocktrans with dupes=info.duplicate_count trimmed %}
            and <abbr title="Duplicate queries are identical to each other: they execute exactly the same SQL and parameters.">{{ dupes }} duplicates</abbr>
          {% endblocktrans %}
        {% endif %}
      {% endif %})
    </li>
  {% endfor %}
</ul>

{% if queries %}
  <table>
    <colgroup>
      <col>
      <col>
      <col>
    </colgroup>
    <thead>
      <tr>
        <th></th>
        <th colspan="2">{% trans "Query" %}</th>
        <th>{% trans "Time (ms)" %}</th>
      </tr>
    </thead>
    <tbody>
      {% for query in queries %}
        <tr class="{% if query.is_slow %} djDebugRowWarning{% endif %}" id="sqlMain_{{ forloop.counter }}">
          <td><span class="djdt-color" data-djdt-styles="backgroundColor:rgb({{ query.rgb_color|join:', '}})"></span></td>
          <td class="djdt-toggle">
            <button type="button" class="djToggleSwitch" data-toggle-name="sqlMain" data-toggle-id="{{ forloop.counter }}">+</button>
          </td>
          <td>
            <div class="djDebugSql">{{ query.sql|safe }}</div>
            {% if query.similar_count %}
              <strong>
                <span class="djdt-color" data-djdt-styles="backgroundColor:{{ query.similar_color }}"></span>
                {% blocktrans with count=query.similar_count %}{{ count }} similar queries.{% endblocktrans %}
              </strong>
            {% endif %}
            {% if query.duplicate_count %}
              <strong>
                <span class="djdt-color" data-djdt-styles="backgroundColor:{{ query.duplicate_color }}"></span>
                {% blocktrans with dupes=query.duplicate_count %}Duplicated {{ dupes }} times.{% endblocktrans %}
              </strong>
            {% endif %}
          </td>
          <td class="djdt-time">
            {{ query.duration|floatformat:"2" }}
          </td>
        </tr>
        <tr class="djUnselected {% if query.is_slow %} djDebugRowWarning{% endif %} djToggleDetails_{{ forloop.counter }}" id="sqlDetails_{{ forloop.counter }}">
          <td colspan="2"></td>
          <td colspan="4">
            <div class="djSQLDetailsDiv">
              <p><strong>{% trans "Connection:" %}</strong> {{ query.alias }}</p>
              {% if query.iso_level %}
                <p><strong>{% trans "Isolation level:" %}</strong> {{ query.iso_level }}</p>
              {% endif %}
              {% if query.trans_status %}
                <p><strong>{% trans "Transaction status:" %}</strong> {{ query.trans_status }}</p>
              {% endif %}
              {% if query.stacktrace %}
                <pre class="djdt-stack">{{ query.stacktrace }}</pre>
              {% endif %}
              {% if query.template_info %}
                <table>
                  {% for line in query.template_info.context %}
                    <tr>
                      <td>{{ line.num }}</td>
                      <td><code {% if line.highlight %}class="djdt-highlighted"{% endif %}>{{ line.content }}</code></td>
                    </tr>
                  {% endfor %}
                </table>
                <p><strong>{{ query.template_info.name|default:_("(unknown)") }}</strong></p>
              {% endif %}
            </div>
          </td>
        </tr>
      {% endfor %}
    </tbody>
  </table>
{% else %}
  <p>{% trans "No MQL queries were recorded during this request." %}</p>
{% endif %}
