{% extends 'base/base.html' %}

{% load static %}

{% block title %}{{ pagename }}{% endblock %}

{% block heading %} Страницы просмотра статистики{% endblock %}

{% block content%}
<div class="mt-5 py-4">
  <div class="container-fluid" style="font-size:2rem">
    <form method="post">
      {% csrf_token %}
      <div class="row g-3">
        <div class="col-auto p-2">
          <h4 class="py-1">{{ form.email.label }}</h4>
        </div>
        <div class="col-auto mt-4">
          {{ form.email }}
        </div>
      </div>
      <div class="row g-3 mt-4">
        <div class="col-auto p-2">
          <h4 class="py-1">{{ form.interval.label }}</h4>
        </div>
        <div class="col-auto">
          {% for radio in form.interval%}
          {{ radio.tag }}
          <label class="btn btn-outline-secondary" for="{{ radio.id_for_label }}">
            {{ radio.choice_label }}
          </label>
          {% endfor %}
        </div>
      </div>
      <div class="row g-3 mt-4">
        <div class="col-auto p-2">
          <h4 class="py-1">{{ form.display_format.label }}</h4>
        </div>
        <div class="col-auto">
          {% for radio in form.display_format%}
          {{ radio.tag }}
          <label class="btn btn-outline-secondary" for="{{ radio.id_for_label }}">
            {{ radio.choice_label }}
          </label>
          {% endfor %}
        </div>
      </div>
      <div class="row g-3 mt-4">
        <div class="col-auto p-2">
          <h4 class="py-1">{{ form.range_start.label}}</h4>
        </div>
        <div class="col-auto">
          <div class='col-sm-7'>
            {{ form.range_start}}
          </div>
        </div>
      </div>
      <div class="row g-3 mt-4">
        <div class="col-auto p-2">
          <h4 class="py-1">{{ form.range_end.label}}</h4>
        </div>
        <div class="col-auto">
          <div class='col-sm-7'>
            {{ form.range_end}}
          </div>
        </div>
      </div>
      <div class="form-row text-center py-5">
        <div class="col-12">
          <button type="submit" class="btn default-button btn-info py-3 px-5">Посмотреть статистику</button>
        </div>
      </div>
    </form>
  </div>
  <ul>
    {% for error in errors %}
      <li><span class="badge bg-danger">{{error}}</span></li>
    {% endfor %}
    </ul>
    <ul>
      {% for warning in warnings %}
        <li><span class="badge bg-warning">{{warning}}</span></li>
      {% endfor %}
    </ul>
  <div class="container-fluid">
    <table class="table table-bordered text-center text-secondary mt-5" style="background-color:#f2f2f2;">
      <thead>
      <tr>
        <td scope="col">&nbsp;</td>
        {% for date in log_stats.keys %}
          <td scope="col">{{ date | date:'d.m' }}</td>
        {% endfor %}
      </tr>
      </thead>
      <tbody>
      <tr>
        <td>{{ form.email.value }}</td>
        {% for time in log_stats.values %}
          <td>{{ time | floatformat:2 }}</td>
        {% endfor %}
      </tr>
      </tbody>
    </table>
  </div>
</div>
{% endblock %}
