{% extends 'layouts/app.html' %}

{% block title %}Admin - Dashboard{% endblock %}

{% block body %}
  <div class="container">
    <div class="row">
      <div class="col-md-4">
        <div class="card">
          <div class="card-header">
            <a href="{{ url_for('admin.coupons') }}">Billing</a>
            <span class="float-right text-muted">
              {{ group_and_count_plans.total }}
            </span>
          </div>
          <div class="card-body">
            <h5 class="mt-2">Subscriptions</h5>
            {% for item in group_and_count_plans.query %}
              {% set percent = ((item[0] / group_and_count_plans.total) * 100) | round %}
              <p class="mt-2 mb-2">
                {{ item[1] | title }}
                <span class="text-muted">({{ item[0] }})</span>
              </p>
              <div class="progress">
                <div class="progress-bar" role="progressbar"
                     aria-valuenow="{{ percent }}" aria-valuemin="0"
                     aria-valuemax="100" style="width: {{ percent }}%;">
                  {{ percent }}%
                </div>
              </div>
            {% endfor %}
            <h5 class="mt-5">
              Coupons
              <a href="{{ url_for('admin.coupons_new') }}"
                 class="btn btn-outline-secondary btn-sm float-right">Add</a>
            </h5>
            <p class="mt-2 mb-2">
              Subscribers are using
              {{ group_and_count_coupons[0] }} coupon(s)
            </p>
            <div class="progress">
              <div class="progress-bar" role="progressbar"
                   aria-valuenow="{{ group_and_count_coupons[2] }}"
                   aria-valuemin="0"
                   aria-valuemax="100"
                   style="width: {{ group_and_count_coupons[2] }}%;">
                {{ group_and_count_coupons[2] }}%
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="card">
          <div class="card-header">
            <a href="{{ url_for('admin.users') }}">Users</a>
            <span class="float-right text-muted">
              {{ group_and_count_users.total }}
            </span>
          </div>
          <div class="card-body">
            {% for item in group_and_count_users.query %}
              {% set percent = ((item[0] / group_and_count_users.total) * 100) | round %}
              <p class="mt-2 mb-2">
                {{ item[1] | title }}
                <span class="text-muted">({{ item[0] }})</span>
              </p>
              <div class="progress mb-4">
                <div class="progress-bar" role="progressbar"
                     aria-valuenow="{{ percent }}" aria-valuemin="0"
                     aria-valuemax="100" style="width: {{ percent }}%;">
                  {{ percent }}%
                </div>
              </div>
            {% endfor %}
          </div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="card">
          <div class="card-header">
            Payouts
            <span class="float-right text-muted">
              {{ group_and_count_payouts.total }}
            </span>
          </div>
          <div class="card-body">
            {% for item in group_and_count_payouts.query %}
              {% set percent = ((item[0] / group_and_count_payouts.total) * 100) | round %}
              <p class="mt-2 mb-2">
                {{ item[1] | title }}x
                <span class="text-muted">({{ item[0] }})</span>
              </p>
              <div class="progress mb-4">
                <div class="progress-bar" role="progressbar"
                     aria-valuenow="{{ percent }}" aria-valuemin="0"
                     aria-valuemax="100" style="width: {{ percent }}%;">
                  {{ percent }}%
                </div>
              </div>
            {% endfor %}
          </div>
        </div>
      </div>
  </div>
</div>
{% endblock %}
