{% extends "base.html" %}
{% block title %}nikola{% endblock %}

{% block content %}
  {% if error %}
    <div class="card">
      <p><strong>Ошибка:</strong></p>
      <p>{{ error }}</p>
    </div>
  {% endif %}

  {% if data %}
    {% for table_name, t in data.items() %}
      {% set rows = t.get("rows", []) %}
      {% set cols = t.get("columns", []) %}

      <div class="card">
        <h3>{{ table_name }} ({{ rows|length }})</h3>

        {% if rows and cols %}
          <div style="overflow:auto; max-width: 100%;">
            <table>
              <tr>
                {% for col in cols %}
                  <td><strong>{{ col }}</strong></td>
                {% endfor %}
              </tr>

              {% for row in rows %}
                <tr>
                  {% for col in cols %}
                    <td>{{ row.get(col) }}</td>
                  {% endfor %}
                </tr>
              {% endfor %}
            </table>
          </div>
        {% else %}
          <p class="muted">таблица пустая</p>
        {% endif %}
      </div>
    {% endfor %}
  {% endif %}
{% endblock %}
