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

    <div class="block-title mb-lg">
      <h1>Contract</h1>
      <span class="block-hash">{{ contract.contract_id }}</span>
    </div>

    <div class="table-section mb-lg">
      <div class="table-header">
        <h3>Contract Info</h3>
        {% if contract.locked %}
        <span class="badge badge-locked">Locked</span>
        {% else %}
        <span class="badge badge-unlocked">Unlocked</span>
        {% endif %}
      </div>
      <div class="table-wrapper">
        <table class="info-table">
          <tbody>
            <tr>
              <td class="info-label">Contract ID</td>
              <td class="hash">{{ contract.contract_id }}</td>
            </tr>
            <tr>
              <td class="info-label">Status</td>
              <td>
                {% if contract.locked %}
                <span class="status-locked">🔒 Locked</span>
                {% else %}
                <span class="status-unlocked">🔓 Unlocked</span>
                {% endif %}
              </td>
            </tr>
            <tr>
              <td class="info-label">WASM Size</td>
              <td>{{ contract.wasm_size_formatted }} ({{ contract.wasm_size }} bytes)</td>
            </tr>
            <tr>
              <td class="info-label">Deploy Block</td>
              <td><a href="/block/{{ contract.deploy_block|int }}">{{ contract.deploy_block|int }}</a></td>
            </tr>
            <tr>
              <td class="info-label">Deploy Transaction</td>
              <td><a href="/tx/{{ contract.deploy_tx }}" class="hash">{{ contract.deploy_tx }}</a></td>
            </tr>
          </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>

  <style>
    .badge-locked {
      background-color: #dc3545;
      color: white;
    }
    .badge-unlocked {
      background-color: #28a745;
      color: white;
    }
    .status-locked {
      color: #dc3545;
      font-weight: bold;
    }
    .status-unlocked {
      color: #28a745;
      font-weight: bold;
    }
  </style>
</body>
</html>
