{% extends "ui/templates/base/layout.html" %}
{% block content %}
<div class="space-y-6">
  <div class="flex flex-wrap items-center justify-between gap-3">
    <div>
      <h2 class="text-xl font-semibold text-slate-900">Peer Review Evidence Preview</h2>
      <p class="text-sm text-slate-500">{{ subscription.client.client_name if subscription.client else '-' }} · {{ subscription.catalogue.service_name if subscription.catalogue else '-' }} · FY {{ subscription.financial_year or '-' }}</p>
    </div>
    <div class="flex flex-wrap gap-2">
      <a href="/peer-review/evidence" class="rounded-xl border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50">Back</a>
      <a href="/peer-review/evidence/{{ subscription.id }}/export.zip" class="rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700">Export ZIP</a>
    </div>
  </div>

  {% if blockers %}
  <section class="rounded-2xl border border-amber-200 bg-amber-50 p-4">
    <h3 class="text-sm font-semibold text-amber-900">Open Blockers</h3>
    <ul class="mt-2 list-disc pl-5 text-sm text-amber-900">
      {% for b in blockers %}<li>{{ b }}</li>{% endfor %}
    </ul>
  </section>
  {% endif %}

  <div class="grid gap-4 md:grid-cols-3">
    <section class="rounded-2xl bg-white p-4 shadow-soft"><p class="text-xs font-semibold uppercase tracking-wide text-slate-500">AQMM Status</p><p class="mt-2 text-lg font-semibold text-slate-900">{{ (subscription.quality_workflow_status or '-')|replace('_',' ')|title }}</p></section>
    <section class="rounded-2xl bg-white p-4 shadow-soft"><p class="text-xs font-semibold uppercase tracking-wide text-slate-500">AQMM Tasks</p><p class="mt-2 text-lg font-semibold text-slate-900">{{ aqmm_tasks|length }}</p></section>
    <section class="rounded-2xl bg-white p-4 shadow-soft"><p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Documents</p><p class="mt-2 text-lg font-semibold text-slate-900">{{ documents|length }}</p></section>
  </div>

  <section class="overflow-hidden rounded-2xl bg-white shadow-soft">
    <div class="border-b border-slate-100 px-5 py-4"><h3 class="text-sm font-semibold text-slate-900">AQMM Task Evidence and Reviews</h3></div>
    <div class="overflow-x-auto">
      <table class="min-w-full divide-y divide-slate-200">
        <thead class="bg-slate-50"><tr><th class="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">Task</th><th class="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">Evidence</th><th class="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">Manager</th><th class="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">Partner</th><th class="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">Review Partner</th></tr></thead>
        <tbody class="divide-y divide-slate-100">
          {% for t in aqmm_tasks %}
          <tr><td class="px-4 py-3 text-sm"><div class="font-medium text-slate-900">{{ t.sequence_no }}. {{ t.task_name }}</div><div class="text-xs text-slate-500">{{ t.aqmm_reference or '' }}</div></td><td class="px-4 py-3 text-sm">{{ (t.evidence_status or '-')|replace('_',' ')|title }}</td><td class="px-4 py-3 text-sm">{{ (t.manager_review_status or '-')|replace('_',' ')|title }}</td><td class="px-4 py-3 text-sm">{{ (t.partner_review_status or '-')|replace('_',' ')|title }}</td><td class="px-4 py-3 text-sm">{{ (t.review_partner_review_status or '-')|replace('_',' ')|title }}</td></tr>
          {% else %}
          <tr><td colspan="5" class="px-4 py-6 text-center text-sm text-slate-500">No AQMM-tagged tasks found.</td></tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </section>

  <section class="overflow-hidden rounded-2xl bg-white shadow-soft">
    <div class="border-b border-slate-100 px-5 py-4"><h3 class="text-sm font-semibold text-slate-900">Documents / UDIN Evidence</h3></div>
    <div class="overflow-x-auto">
      <table class="min-w-full divide-y divide-slate-200">
        <thead class="bg-slate-50"><tr><th class="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">Document</th><th class="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">AQMM Evidence</th><th class="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">Release</th><th class="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">UDIN</th></tr></thead>
        <tbody class="divide-y divide-slate-100">
          {% for d in documents %}
          <tr><td class="px-4 py-3 text-sm"><div class="font-medium text-slate-900">{{ d.title }}</div><div class="text-xs text-slate-500">{{ d.document_code }} · {{ d.document_type }}</div></td><td class="px-4 py-3 text-sm">{{ 'Yes' if d.is_aqmm_evidence else 'No' }} · {{ (d.evidence_status or '-')|replace('_',' ')|title }}</td><td class="px-4 py-3 text-sm">{{ (d.final_release_status or '-')|replace('_',' ')|title }}</td><td class="px-4 py-3 text-sm">{{ d.udin_number or (d.udin_status or '-') }}</td></tr>
          {% else %}
          <tr><td colspan="4" class="px-4 py-6 text-center text-sm text-slate-500">No documents found.</td></tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </section>
</div>
{% endblock %}
