{% extends "base.html" %}

{% block title %}处理历史{% endblock %}

{% block content %}
  <section class="page-header">
    <span class="eyebrow">Processing History</span>
    <h1 class="page-title">处理历史</h1>
    <p class="page-lead">按批次、产品和会话回看审核执行、结构化结论与通知留痕。</p>
  </section>

  <section class="panel">
    <div class="section-heading">
      <div>
        <h2 class="section-title">历史筛选</h2>
        <p class="section-copy">支持按产品名称或批次号搜索。</p>
      </div>
    </div>
    <form method="get" class="grid-2">
      <div>
        <label for="id_keyword">产品名称 / 批次号</label>
        <input id="id_keyword" type="text" name="keyword" value="{{ keyword }}" placeholder="例如：新型冠状病毒 或 SUB-20260604-001">
      </div>
      <div class="button-row" style="align-items: end;">
        <button type="submit">筛选历史</button>
        <a class="button" href="{% url 'audit:list' %}">清空</a>
      </div>
    </form>
  </section>

  <section class="panel">
    <div class="section-heading">
      <div>
        <h2 class="section-title">执行快照列表</h2>
        <p class="section-copy">围绕 `batch_id / conversation_id / product_name` 展示处理历史。</p>
      </div>
    </div>
    <div class="table-wrap">
      <table class="data-table">
        <thead>
          <tr>
            <th>ID</th>
            <th>场景</th>
            <th>产品名称</th>
            <th>批次号</th>
            <th>会话</th>
            <th>输入摘要</th>
            <th>状态</th>
            <th>模型</th>
            <th>时间</th>
            <th>详情</th>
          </tr>
        </thead>
        <tbody>
          {% for log in logs %}
            <tr>
              <td>{{ log.id }}</td>
              <td>{{ log.scenario_name }}</td>
              <td>{{ log.product_name|default:"-" }}</td>
              <td>{{ log.batch_id|default:"-" }}</td>
              <td>{{ log.conversation_id|default:"-" }}</td>
              <td>{{ log.get_user_input_summary }}</td>
              <td>
                <span class="pill {% if log.status == 'success' %}pill-success{% else %}pill-danger{% endif %}">{{ log.get_status_display_text }}</span>
              </td>
              <td>{{ log.model_name }}</td>
              <td>{{ log.created_at|date:"Y-m-d H:i" }}</td>
              <td><a class="button" href="{% url 'audit:detail' log.id %}">查看详情</a></td>
            </tr>
          {% empty %}
            <tr><td colspan="10">暂无处理历史，先去执行一次审核任务。</td></tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </section>
{% endblock %}
