<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>DarkFi Blocks - Statistics</title>
  <link rel="stylesheet" href="/static/layout.css">
</head>
<body>
  <header class="header">
    <div class="container flex justify-between items-center">
      <div class="logo">DarkFi {{ network }} Blocks</div>
      <nav class="nav">
        <a href="/">Explorer</a>
        <a href="/contracts">Contracts</a>
        <a href="/stats" class="active">Stats</a>
        <a href="https://dark.fi/book/">Docs</a>
        <a href="https://codeberg.org/darkrenaissance/darkfi/">Code</a>
      </nav>
    </div>
  </header>

  <main class="container section">

    <form action="/search" method="GET" class="input-group mb-lg" style="max-width: 600px;">
      <input type="search" name="q" class="input" placeholder="Search by block height, hash, transaction, or contract ID...">
      <button type="submit" class="btn">Search</button>
    </form>

    <div class="stats-grid mb-lg">
      <div class="stat-card">
        <div class="label">Difficulty</div>
        <div class="value">{{ current_difficulty }}</div>
      </div>
      <div class="stat-card">
        <div class="label">Height</div>
        <div class="value">{{ current_height }}</div>
      </div>
      <div class="stat-card">
        <div class="label">Hashrate</div>
        <div class="value">{{ hashrate|default('n/a') }}</div>
      </div>
      <div class="stat-card">
        <div class="label">Emission</div>
        <div class="value">n/a</div>
      </div>
    </div>

    <h1 class="mb-lg">Blockchain Statistics</h1>

    <div class="table-section mb-lg">
      <div class="table-header">
        <h3>Daily Average Transactions per Block (Last 90 Days)</h3>
      </div>
      <div class="chart-container" style="text-align: center; padding: 1rem;">
        <img src="/stats/daily_tx_chart.png" alt="Daily Average Transactions Chart" style="max-width: 100%; height: auto;">
      </div>
    </div>

    <div class="table-section mb-lg">
      <div class="table-header">
        <h3>Transactions per Block (Excluding Coinbase)</h3>
      </div>
      <div class="table-wrapper">
        <table>
          <thead>
            <tr>
              <th>Period</th>
              <th>Avg TX/Block</th>
              <th>Empty Blocks %</th>
              <th>Total Transactions</th>
              <th>Blocks</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>Last Day</td>
              <td>{{ "%.2f"|format(stats.tx_per_block.last_day.avg_tx) }}</td>
              <td>{{ "%.1f"|format(stats.tx_per_block.last_day.empty_pct) }}%</td>
              <td>{{ stats.tx_per_block.last_day.total_tx|int }}</td>
              <td>{{ stats.tx_per_block.last_day.block_count|int }}</td>
            </tr>
            <tr>
              <td>Last Week</td>
              <td>{{ "%.2f"|format(stats.tx_per_block.last_week.avg_tx) }}</td>
              <td>{{ "%.1f"|format(stats.tx_per_block.last_week.empty_pct) }}%</td>
              <td>{{ stats.tx_per_block.last_week.total_tx|int }}</td>
              <td>{{ stats.tx_per_block.last_week.block_count|int }}</td>
            </tr>
            <tr>
              <td>Last Month</td>
              <td>{{ "%.2f"|format(stats.tx_per_block.last_month.avg_tx) }}</td>
              <td>{{ "%.1f"|format(stats.tx_per_block.last_month.empty_pct) }}%</td>
              <td>{{ stats.tx_per_block.last_month.total_tx|int }}</td>
              <td>{{ stats.tx_per_block.last_month.block_count|int }}</td>
            </tr>
            <tr>
              <td>Last Year</td>
              <td>{{ "%.2f"|format(stats.tx_per_block.last_year.avg_tx) }}</td>
              <td>{{ "%.1f"|format(stats.tx_per_block.last_year.empty_pct) }}%</td>
              <td>{{ stats.tx_per_block.last_year.total_tx|int }}</td>
              <td>{{ stats.tx_per_block.last_year.block_count|int }}</td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>

    <div class="table-section mb-lg">
      <div class="table-header">
        <h3>Blockchain Growth by Month</h3>
      </div>
      <div class="table-wrapper" style="max-height: 400px; overflow-y: auto;">
        <table>
          <thead>
            <tr>
              <th>Month</th>
              <th>Monthly Growth (MB)</th>
              <th>Cumulative Size (MB)</th>
            </tr>
          </thead>
          <tbody>
            {% for month in stats.monthly_growth|reverse %}
            <tr>
              <td>{{ month.year|int }}-{{ "%02d"|format(month.month|int) }}</td>
              <td>{{ "%.2f"|format(month.size_mb) }}</td>
              <td>{{ "%.2f"|format(month.cumulative_mb) }}</td>
            </tr>
            {% else %}
            <tr>
              <td colspan="3" style="text-align: center; color: var(--color-muted);">No data available</td>
            </tr>
            {% endfor %}
          </tbody>
        </table>
      </div>
    </div>

  </main>

  <footer class="footer">
    <div class="container">
      <a href="https://dark.fi">Let there be Dark</a> · Code licensed under AGPL-3
    </div>
  </footer>

</body>
</html>
