{% extends "base.html" %}
{% block title %}Ledger — psyc{% endblock %}
{% block content %}
<section class="panel">
  <div class="panel-head">
    <h1>Immutable Audit Ledger</h1>
    <span class="count">{{ total }} entr{{ 'y' if total == 1 else 'ies' }}</span>
  </div>
  <p class="page-intro">The append-only audit trail. Every external submission and every policy-blocked route is recorded here — nothing leaves psyc without a row. This is the platform's proof of exactly what happened, when, and to whom.</p>
  <details class="page-help">
    <summary>how to use this view</summary>
    <div class="help-body">
      <p><b>How to use.</b> Read top-down, newest first. Each row is one external submission or one policy-blocked route. Open a case to see only its entries.</p>
      <p><b>What you're seeing.</b> timestamp · case · destination · payload hash · submitter · TLP · outcome — written by Ledgerline the moment Courier acts.</p>
      <p><b>Why it matters.</b> Defensive operations must be provable. The ledger is append-only — psyc can show exactly what it sent, where, and what came back.</p>
    </div>
  </details>
  {% if not entries %}
    <p class="empty">No ledger entries yet. Run <code>psyc submit &lt;case_id&gt;</code> or <code>psyc demo</code>.</p>
  {% else %}
  <table class="ledger">
    <thead>
      <tr>
        <th>Timestamp</th>
        <th>Case</th>
        <th>Destination</th>
        <th>Payload hash</th>
        <th>Submitter</th>
        <th>TLP</th>
        <th>Outcome</th>
      </tr>
    </thead>
    <tbody>
    {% for e in entries %}
      <tr class="ledger-row{% if e.outcome.value == 'rejected' %} is-rejected{% elif e.outcome.value == 'actioned' %} is-actioned{% endif %}">
        <td class="lg-ts">{{ e.timestamp.strftime('%Y-%m-%d %H:%M:%S') }}</td>
        <td class="lg-case"><a href="/cases/{{ e.case_id }}">{{ e.case_id }}</a></td>
        <td class="lg-dest">{{ e.destination }}</td>
        <td class="lg-hash">{{ e.payload_hash or '—' }}</td>
        <td class="lg-sub">{{ e.submitter_identity }}</td>
        <td><span class="tlp-badge tlp-{{ e.tlp.value }}">{{ e.tlp.value }}</span></td>
        <td><span class="outcome-badge outcome-{{ e.outcome.value }}">{{ e.outcome.value }}</span></td>
      </tr>
    {% endfor %}
    </tbody>
  </table>
  {% endif %}
</section>
{% endblock %}
