{% from "components/table.html" import list_table, field, right_aligned_field_heading, row_heading %}
{% from "components/big-number.html" import big_number -%}

<div class='dashboard-table ajax-block-container'>
  {% call(item, row_number) list_table(
    jobs,
    caption="Recent files uploaded",
    caption_visible=False,
    empty_message='You haven’t uploaded any files recently',
    field_headings=[
      'File',
      'Sending',
      'Delivered',
      'Failed'
    ],
    field_headings_visible=True
  ) %}
    {% call row_heading() %}
      <div class="file-list">
        <a class="file-list-filename" href="{{ url_for('.view_job', service_id=current_service.id, job_id=item.id) }}">{{ item.original_file_name }}</a>
        <span class="file-list-hint">
          Sent {{
            item.scheduled_for|format_datetime_short if item.scheduled_for else item.created_at|format_datetime_short
          }}
        </span>
      </div>
    {% endcall %}
    {% call field() %}
      {{ big_number(
        item.get('notification_count', 0) - item.get('notifications_delivered', 0) - item.get('notifications_failed', 0),
        smallest=True
      ) }}
    {% endcall %}
    {% call field() %}
      {{ big_number(item.get('notifications_delivered', 0), smallest=True) }}
    {% endcall %}
    {% call field(status='error' if item.get('failure_rate', 0) > 3 else '') %}
      {{ big_number(item.get('notifications_failed', 0), smallest=True) }}
    {% endcall %}
  {% endcall %}
</div>
