{% extends 'base.html' %}
{% block content %}
<div class="container py-4">
  <h3>访问日志 - {{ domain.name }}</h3>
  <form class="row g-3 mb-3" method="get">
    <div class="col-md-2">
      <label class="form-label">日期(YYYYMMDD)</label>
      <input type="text" name="day" value="{{ day }}" class="form-control" placeholder="20251117">
    </div>
    <div class="col-md-2">
      <label class="form-label">开始小时</label>
      <input type="text" name="hour_from" value="{{ hour_from }}" class="form-control" placeholder="00">
    </div>
    <div class="col-md-2">
      <label class="form-label">结束小时</label>
      <input type="text" name="hour_to" value="{{ hour_to }}" class="form-control" placeholder="23">
    </div>
    <div class="col-md-2">
      <label class="form-label">IP</label>
      <input type="text" name="ip" value="{{ ip }}" class="form-control" placeholder="1.2.3.4">
    </div>
    <div class="col-md-3">
      <label class="form-label">关键词</label>
      <input type="text" name="keyword" value="{{ keyword }}" class="form-control" placeholder="path or UA">
    </div>
    <div class="col-md-2">
      <label class="form-label">状态码</label>
      <input type="text" name="status_code" value="{{ status_code }}" class="form-control" placeholder="200">
    </div>
    <div class="col-md-1">
      <label class="form-label">条数</label>
      <input type="number" name="size" value="{{ size }}" class="form-control" min="1" max="200">
    </div>
    <div class="col-md-2 d-flex align-items-end">
      <div class="form-check">
        <input class="form-check-input" type="checkbox" name="reverse" value="1" {% if reverse %}checked{% endif %} id="revCheck">
        <label class="form-check-label" for="revCheck">反向</label>
      </div>
    </div>
    <div class="col-md-10 d-flex align-items-end justify-content-end gap-2">
      <button type="submit" class="btn btn-primary">查询</button>
      <a class="btn btn-outline-secondary" href="?day={{ day }}&hour_from={{ hour_from }}&hour_to={{ hour_to }}&ip={{ ip }}&keyword={{ keyword }}&status_code={{ status_code }}&size={{ size }}&reverse={{ reverse|yesno:'1,0' }}&export=csv">导出 CSV</a>
      <a class="btn btn-outline-secondary" href="?day={{ day }}&hour_from={{ hour_from }}&hour_to={{ hour_to }}&ip={{ ip }}&keyword={{ keyword }}&status_code={{ status_code }}&size={{ size }}&reverse={{ reverse|yesno:'1,0' }}&export=json">导出 JSON</a>
    </div>
  </form>

  <div class="table-responsive">
    <table class="table table-sm table-striped">
      <thead>
        <tr>
          <th>时间</th>
          <th>域名</th>
          <th>IP</th>
          <th>方法</th>
          <th>路径</th>
          <th>状态码</th>
          <th>字节数</th>
          <th>UA</th>
        </tr>
      </thead>
      <tbody>
        {% for log in logs %}
        <tr>
          <td>{{ log.timeLocal }}</td>
          <td>{{ log.host }}</td>
          <td>{{ log.remoteAddr }}</td>
          <td>{{ log.method }}</td>
          <td>{{ log.requestURI }}</td>
          <td>{{ log.status }}</td>
          <td>{{ log.bytesSent }}</td>
          <td>{{ log.userAgent }}</td>
        </tr>
        {% empty %}
        <tr><td colspan="8" class="text-center">无数据</td></tr>
        {% endfor %}
      </tbody>
    </table>
  </div>

  {% if has_more and request_id %}
  <div class="d-flex justify-content-end">
    <a class="btn btn-outline-secondary" href="?day={{ day }}&hour_from={{ hour_from }}&hour_to={{ hour_to }}&ip={{ ip }}&keyword={{ keyword }}&status_code={{ status_code }}&size={{ size }}&reverse={{ reverse|yesno:'1,0' }}&request_id={{ request_id }}">下一页</a>
  </div>
  {% endif %}
</div>
{% endblock %}