{% extends "base.html" %}

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

{% block content %}
  <section class="page-header">
    <span class="eyebrow">History Detail</span>
    <h1 class="page-title">处理历史 #{{ log.id }}</h1>
    <p class="page-lead">集中展示本次执行的业务上下文、结构化结果、引用来源与通知留痕。</p>
    <div class="badge-row">
      <span class="pill pill-accent">批次：{{ log.batch_id|default:"-" }}</span>
      <span class="pill">会话：{{ log.conversation_id|default:"-" }}</span>
      <span class="pill">产品：{{ log.product_name|default:"-" }}</span>
    </div>
  </section>

  <section class="grid-2">
    <article class="panel">
      <h2 class="section-title">执行上下文</h2>
      <ul class="detail-list">
        <li class="detail-item"><strong>用户输入</strong><div>{{ log.user_input|linebreaksbr }}</div></li>
        <li class="detail-item"><strong>最终回答</strong><div>{{ log.final_answer|linebreaksbr }}</div></li>
        <li class="detail-item"><strong>结构化输出</strong><pre class="code-block">{{ log.structured_output }}</pre></li>
      </ul>
    </article>

    <article class="panel">
      <h2 class="section-title">执行证据</h2>
      <ul class="detail-list">
        <li class="detail-item"><strong>引用来源</strong><pre class="code-block">{{ log.retrieved_chunks }}</pre></li>
        <li class="detail-item"><strong>工具调用</strong><pre class="code-block">{{ log.tool_calls }}</pre></li>
        <li class="detail-item"><strong>原始输出</strong><pre class="code-block">{{ log.raw_output }}</pre></li>
      </ul>
    </article>
  </section>

  <section class="panel">
    <h2 class="section-title">会话节点结果</h2>
    <ul class="detail-list">
      {% if conversation and conversation.node_results %}
        {% for node in conversation.node_results %}
          <li class="detail-item">
            <strong>{{ node.label }} / {{ node.status }}</strong>
            {% if node.summary %}
              <div>{{ node.summary }}</div>
            {% endif %}
          </li>
        {% endfor %}
      {% else %}
        <li class="detail-item">当前会话暂无节点结果。</li>
      {% endif %}
    </ul>
  </section>

  <section class="grid-2">
    <article class="panel">
      <h2 class="section-title">导出状态摘要</h2>
      <ul class="detail-list">
        <li class="detail-item"><strong>导出状态</strong><div>{{ detail_summary.export_status|default:"-" }}</div></li>
        <li class="detail-item"><strong>输出文件名</strong><div>{{ detail_summary.output_file_name|default:"-" }}</div></li>
        <li class="detail-item"><strong>导出模式</strong><div>{{ detail_summary.export_mode|default:"-" }}</div></li>
        <li class="detail-item"><strong>模板名称</strong><div>{{ detail_summary.template_name|default:"-" }}</div></li>
        <li class="detail-item"><strong>模板版本</strong><div>{{ detail_summary.template_version|default:"-" }}</div></li>
        <li class="detail-item"><strong>草稿导出状态</strong><div>{{ detail_summary.draft_export_status|default:"-" }}</div></li>
        <li class="detail-item"><strong>正式导出状态</strong><div>{{ detail_summary.formal_export_status|default:"-" }}</div></li>
        <li class="detail-item"><strong>下载地址</strong><div>{{ detail_summary.download_url|default:"-" }}</div></li>
        <li class="detail-item">
          <strong>阻断项</strong>
          {% if detail_summary.blocked_items %}
            <div>{{ detail_summary.blocked_items|join:" / " }}</div>
          {% else %}
            <div>-</div>
          {% endif %}
        </li>
      </ul>
    </article>

    <article class="panel">
      <h2 class="section-title">通知回执</h2>
      <pre class="code-block">{{ detail_summary.notification_receipt }}</pre>
    </article>
  </section>

  <section class="panel">
    <h2 class="section-title">通知留痕</h2>
    <div class="table-wrap">
      <table class="data-table">
        <thead>
          <tr>
            <th>触发原因</th>
            <th>责任角色</th>
            <th>飞书用户</th>
            <th>消息状态</th>
            <th>详情链接</th>
          </tr>
        </thead>
        <tbody>
          {% for item in notifications %}
            <tr>
              <td>{{ item.notify_reason }}</td>
              <td>{{ item.owner_role }}</td>
              <td>{{ item.feishu_user_id }}</td>
              <td>{{ item.message_status }}</td>
              <td>{{ item.web_detail_url|default:"-" }}</td>
            </tr>
          {% empty %}
            <tr><td colspan="5">当前执行尚无通知留痕。</td></tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </section>
{% endblock %}
