{% from "common/macros/status.html" import submissionStatusTag, assessmentStatusTag with context %}
{% from "common/macros/timeline.html" import timeline with context %}
{% extends 'admin/model/details.html' %}

{% block details_table %}
  <dl class="app-metadata">
    <dt class="app-metadata__key">Grant:</dt>
    <dd class="app-metadata__value" data-testid="submission-status">{{ model.collection.grant.name }}</dd>
  </dl>
  <dl class="app-metadata">
    <dt class="app-metadata__key">Collection:</dt>
    <dd class="app-metadata__value" data-testid="submission-status">{{ model.collection.name }}</dd>
  </dl>
  <dl class="app-metadata">
    <dt class="app-metadata__key">Organisation:</dt>
    <dd class="app-metadata__value" data-testid="submission-status">{{ model.grant_recipient.organisation.name if model.grant_recipient else "None" }}</dd>
  </dl>
  <dl class="app-metadata">
    <dt class="app-metadata__key">Reference:</dt>
    <dd class="app-metadata__value" data-testid="submission-status">{{ model.reference }}</dd>
  </dl>
  {% if helper.is_submitted %}
    <dl class="app-metadata">
      <dt class="app-metadata__key">Submitted by:</dt>
      <dd class="app-metadata__value" data-testid="submission-status">{{ helper.submitted_by.name }}</dd>
    </dl>
    {% if helper.certified_by %}
      <dl class="app-metadata">
        <dt class="app-metadata__key">Certified by:</dt>
        <dd class="app-metadata__value" data-testid="submission-status">{{ helper.certified_by.name }}</dd>
      </dl>
    {% endif %}
    <dl class="app-metadata">
      <dt class="app-metadata__key">Date submitted:</dt>
      <dd class="app-metadata__value" data-testid="submission-status">{{ format_date(helper.submitted_at_utc) }}</dd>
    </dl>
  {% elif helper.is_awaiting_sign_off %}
    <dl class="app-metadata">
      <dt class="app-metadata__key">Submitted by:</dt>
      <dd class="app-metadata__value" data-testid="submission-status">{{ helper.sent_for_certification_by.name }}</dd>
    </dl>
    <dl class="app-metadata">
      <dt class="app-metadata__key">Date submitted for sign off:</dt>
      <dd class="app-metadata__value" data-testid="submission-status">{{ format_date(helper.sent_for_certification_at_utc) }}</dd>
    </dl>
  {% endif %}
  <dl class="app-metadata">
    <dt class="app-metadata__key">Status:</dt>
    <dd class="app-metadata__value" data-testid="submission-status">{{ submissionStatusTag(helper.status, helper.submission.is_overdue) }}</dd>
  </dl>
  <dl class="app-metadata">
    <dt class="app-metadata__key">Assessment status:</dt>
    <dd class="app-metadata__value" data-testid="assessment-status">{{ assessmentStatusTag(helper.assessment_status) }}</dd>
  </dl>

  {% if not helper.is_preview %}
    <hr class="govuk-section-break govuk-section-break--visible govuk-section-break--l" />

    {{ timeline(helper.timeline_events, timeline_event_types) }}
  {% endif %}
{% endblock %}
