<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>DarkFi Blocks - Block Explorer</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">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, or transaction...">
      <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>

    <div class="block-title mb-lg">
      <h1>Transaction</h1>
      <span class="block-hash">{{ tx.hash }}</span>
    </div>

    <div class="tx-grid mb-lg">
      <div class="table-section">
        <div class="table-header">
          <h3>Transaction Info</h3>
        </div>
        <div class="table-wrapper">
          <table class="info-table">
            <tbody>
              <tr>
                <td class="info-label">Confirmations</td>
                <td>{{ tx.confirmations }}</td>
              </tr>
              <tr>
                <td class="info-label">From Block</td>
                <td><a href="/block/{{ tx.from_block }}">{{ tx.from_block }}</a></td>
              </tr>
              <tr>
                <td class="info-label">Fee</td>
                <td>{{ tx.fee }}</td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>

      <div class="table-section">
        <div class="table-header">
          <h3>Contract Calls ({{ tx.n_calls }})</h3>
        </div>
        <div class="contract-calls">
        {% for call in tx.calls %}
          <div class="call-item">
            <div class="call-index">{{ loop.index0 }}</div>
            <div class="call-details">
              <div class="call-row">
                <span class="call-label">Contract ID</span>
                <span class="call-value"><a href="#" class="hash">{{ call.contract_id }}</a>
                {% if call.contract_tag %}
                  <span class="contract-tag">{{ call.contract_tag }}</span>
                {% endif %}
                </span>
                <div class="call-row">
                  <span class="call-label">Data</span>
                  <span class="call-value"><span class="call-byte">{{ call.func }}</span> {{ call.size }}</span>
                </div>
              </div>
            </div>
          </div>
        {% endfor %}
        </div>
      </div>
    </div>

    <div class="table-section">
      <div class="table-header">
        <h3>Raw Transaction</h3>
      </div>
      <div class="code-block">
        <code>{{ tx.raw }}</code>
      </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>
