{% extends "_base.html" %}

{% block body %}
<div class="row">
  <div class="col">
    <h2 class="mb-3">{{ query.title }}</h2>

    <form action="{{ request.url.path }}" method="get">
      <div class="mb-3">
        <textarea disabled name="sql" rows="5" class="form-control">{{ query.sql }}</textarea>
      </div>

      <div class="mb-3">
        <div class="d-flex justify-content-end">
          <button type="submit" class="btn btn-primary">Execute</button>
        </div>
      </div>
    </form>

    {% if error %}
    <div class="alert alert-danger" role="alert">
      {{ error.message }}
    </div>
    {% else %}
    <div class="table-responsive">
      <table class="table table-sm table-bordered table-striped table-hover">
        <thead>
          <tr>
            {% for column in query_results.columns %}
            <th>{{ column }}</th>
            {% endfor %}
          </tr>
        </thead>
        <tbody class="table-group-divider">
          {% for row in query_results.to_numpy().tolist() %}
          <tr>
            {% for col in row %}
            <td>{{ col }}</td>
            {% endfor %}
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
    {% endif %}
  </div>
</div>
{% endblock %}