{{define "audit"}}
<div class="card">
  <div class="section-title">
    <div>
      <div class="crumb">系统管理 / 日志审计 / 审计记录</div>
      <h2 class="title-with-icon">{{icon "audit"}}<span>审计记录</span></h2>
    </div>
  </div>
  <div class="table-wrap">
    {{if .AuditEntries}}
    <table>
      <thead>
        <tr>
          <th>动作</th>
          <th>目标</th>
          <th>任务</th>
          <th>配置</th>
          <th>结果</th>
        </tr>
      </thead>
      <tbody>
        {{range .AuditEntries}}
        <tr>
          <td>{{auditActionLabel .Action}}</td>
          <td><span class="mono">{{.TargetID}}</span></td>
          <td class="mono">{{if auditField .DetailsJSON "task_id"}}{{auditField .DetailsJSON "task_id"}}{{else}}-{{end}}</td>
          <td class="mono">{{if auditField .DetailsJSON "profile"}}{{auditField .DetailsJSON "profile"}}{{else if auditField .DetailsJSON "config_id"}}{{auditField .DetailsJSON "config_id"}}{{else}}-{{end}}</td>
          <td>{{if auditField .DetailsJSON "status"}}{{auditStatusLabel (auditField .DetailsJSON "status")}}{{else}}{{.Actor}}{{end}}</td>
        </tr>
        {{end}}
      </tbody>
    </table>
    {{else}}
    <table>
      <thead>
        <tr>
          <th>类型</th>
          <th>任务</th>
          <th>目标设备数</th>
          <th>结果</th>
          <th>说明</th>
        </tr>
      </thead>
      <tbody>
        {{range .Tasks}}
        <tr>
          <td>
            <span class="{{taskGroupClass .Type}}">{{taskGroupLabel .Type}}</span>
            <div class="muted small" style="margin-top:4px">{{taskActionLabel .Type}}</div>
          </td>
          <td>
            <div class="mono">{{.ID}}</div>
          </td>
          <td>{{len .DeviceIDs}} 台</td>
          <td><span class="{{taskStatusClass .Status}}">{{taskStatusLabel .Status}}</span></td>
          <td class="muted small">{{if .Payload}}已记录任务参数{{else}}无附加参数{{end}}</td>
        </tr>
        {{else}}
        <tr>
          <td colspan="5">
            <div class="empty-state">
              <div class="empty-title">暂无审计记录</div>
              <div class="muted">当前后台还没有记录到任何任务或设备操作。</div>
            </div>
          </td>
        </tr>
        {{end}}
      </tbody>
    </table>
    {{end}}
  </div>
</div>
{{end}}
