{% extends 'ewoooc_base.html' %}

{% block title %}系統事件紀錄 · EwoooC{% endblock %}
{% block page_accent %}observability{% endblock %}

{% block extra_css %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/page-logs.css') }}">
{% endblock %}

{% block content %}
<div class="page-logs">

  <header class="page-header">
    <h4><i class="fas fa-clipboard-list me-2"></i>系統事件紀錄</h4>
    <div class="status-indicators">
      <div class="status-item">
        <span class="status-dot"></span>
        <span id="connection-status">資料連線正常</span>
      </div>
      <div class="status-item">
        <i class="fas fa-clock"></i>
        <span id="last-update">最後更新: --</span>
      </div>
    </div>
  </header>

  <section class="stats-grid">
    {% set stats = [
      ('total',   'fa-list',                'total-lines',   '事件數'),
      ('error',   'fa-exclamation-circle',  'error-count',   '需處理'),
      ('warning', 'fa-exclamation-triangle','warning-count', '需追蹤'),
      ('info',    'fa-info-circle',         'info-count',    '一般')
    ] %}
    {% for kind, icon, vid, label in stats %}
    <article class="stat-card stat-card--{{ kind }}">
      <div class="stat-icon"><i class="fas {{ icon }}"></i></div>
      <div class="stat-content">
        <div class="stat-value" id="{{ vid }}">0</div>
        <div class="stat-label">{{ label }}</div>
      </div>
    </article>
    {% endfor %}
  </section>

  <section class="control-panel">
    <div class="control-section">
      <div class="control-section-title">事件操作</div>
      <div class="control-buttons">
        <button class="btn-control btn-control--refresh" onclick="refreshLogs()" aria-label="立即刷新">
          <i class="fas fa-sync-alt"></i><span>立即刷新</span>
        </button>
        <button class="btn-control btn-control--pause" id="pause-btn" onclick="toggleAutoRefresh()" aria-label="暫停自動刷新">
          <i class="fas fa-pause"></i><span>暫停自動刷新</span>
        </button>
        <button class="btn-control btn-control--clear" onclick="clearLogs()" aria-label="清除畫面">
          <i class="fas fa-eraser"></i><span>清除畫面</span>
        </button>
        <button class="btn-control btn-control--download" onclick="downloadLogs()" aria-label="下載事件摘要">
          <i class="fas fa-download"></i><span>下載事件摘要</span>
        </button>
      </div>
    </div>

    <div class="control-section">
      <div class="control-section-title">事件篩選</div>
      <div class="filter-row">
        <div class="filter-buttons">
          {% for level, icon, label in [
            ('all',     'fa-list',                '全部'),
            ('error',   'fa-exclamation-circle',  '需處理'),
            ('warning', 'fa-exclamation-triangle','需追蹤'),
            ('info',    'fa-info-circle',         '一般')
          ] %}
          <button class="btn-filter btn-filter--{{ level }}{% if level == 'all' %} is-active{% endif %}"
                  data-level="{{ level }}" onclick="filterByLevel('{{ level }}')">
            <i class="fas {{ icon }} me-1"></i>{{ label }}
          </button>
          {% endfor %}
        </div>
        <div class="search-box" id="search-box">
          <i class="fas fa-search search-icon"></i>
          <input type="text" id="search-input" placeholder="搜尋事件、服務或處置..." oninput="searchLogs()">
          <i class="fas fa-times clear-icon" onclick="clearSearch()"></i>
        </div>
      </div>
    </div>

    <div class="control-section control-section--last">
      <div class="control-section-title">閱讀設定</div>
      <div class="display-row">
        <div class="font-size-group">
          <span class="form-hint">字體大小：</span>
          <div class="font-size-controls">
            {% for size, label in [('small','小'), ('medium','中'), ('large','大')] %}
            <button class="btn-font-size{% if size == 'medium' %} is-active{% endif %}"
                    data-size="{{ size }}" onclick="changeFontSize('{{ size }}')">{{ label }}</button>
            {% endfor %}
          </div>
        </div>
        <div class="toggle-group">
          <div class="toggle-item">
            <label class="toggle-switch">
              <input type="checkbox" id="auto-scroll-toggle" checked onchange="toggleAutoScroll()">
              <span class="slider"></span>
            </label>
            <span class="toggle-label">自動跟隨最新事件</span>
          </div>
        </div>
      </div>
    </div>
  </section>

  <section class="log-container-wrapper">
    <div id="log-container" class="font-medium">
      <div class="log-empty">
        <i class="fas fa-clipboard-list"></i>
        <p>正在載入事件紀錄...</p>
      </div>
    </div>
  </section>

</div>
{% endblock %}

{% block extra_js %}
<script src="{{ url_for('static', filename='js/page-logs.js') }}"></script>
{% endblock %}
