{% from "components/message-count-label.html" import message_count_label %}
{% from "components/pill.html" import pill %}
{% from "components/table.html" import list_table, field, right_aligned_field_heading, row_heading, spark_bar_field %}

{% extends "withnav_template.html" %}

{% block service_page_title %}
  Templates used
{% endblock %}

{% block maincolumn_content %}

  <h1 class="heading-large">Templates used</h1>

  <div class="bottom-gutter-3-2">
    {{ pill(
      items=years,
      current_value=selected_year,
      big_number_args={'smallest': True},
    ) }}
  </div>

  <div class="dashboard">
    {% for month in months %}
      <h2>{{ month.name }}</h2>
      {% if not month.templates_used %}
        <p class="table-no-data">
          No messages sent
        </p>
      {% else %}
        <div class='dashboard-table template-usage-table'>
          {% call(item, row_number) list_table(
            month.templates_used,
            caption=month.name,
            caption_visible=False,
            empty_message='',
            field_headings=[
              'Template',
              'Messages sent'
            ],
            field_headings_visible=False
          ) %}
            {% call row_heading() %}
              <span class="spark-bar-label">
                <a href="{{ url_for('.view_template', service_id=current_service.id, template_id=item.id) }}">{{ item.name }}</a>
                <span class="file-list-hint">
                  {{ message_count_label(1, item.type, suffix='template')|capitalize }}
                </span>
              </span>
            {% endcall %}
            {{ spark_bar_field(item.requested_count, most_used_template_count) }}
          {% endcall %}
        </div>
      {% endif %}
    {% endfor %}
  </div>

{% endblock %}
