<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>比特币区块链浏览器</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }
        .search-form {
            display: flex;
        }
        .search-form input {
            padding: 8px;
            width: 300px;
            border: 1px solid #ddd;
            border-radius: 4px 0 0 4px;
        }
        .search-form button {
            padding: 8px 15px;
            background-color: #f7931a;
            color: white;
            border: none;
            border-radius: 0 4px 4px 0;
            cursor: pointer;
        }
        .info-panel {
            background-color: #f9f9f9;
            border-radius: 4px;
            padding: 20px;
            margin-bottom: 20px;
        }
        .block-list {
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        .block-list table {
            width: 100%;
            border-collapse: collapse;
        }
        .block-list th, .block-list td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        .block-list th {
            background-color: #f2f2f2;
        }
        a {
            color: #0366d6;
            text-decoration: none;
        }
        a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <header>
        <h1>比特币区块链浏览器</h1>
        <form class="search-form" action="/search" method="get">
            <input type="text" name="q" placeholder="搜索区块高度、区块哈希或交易ID">
            <button type="submit">搜索</button>
        </form>
    </header>

    <div class="info-panel">
        <h2>区块链信息</h2>
        <p>当前区块高度: {{ blockchain_info.blocks }}</p>
        <p>当前难度: {{ blockchain_info.difficulty }}</p>
        <p>同步进度: {{ (blockchain_info.verificationprogress * 100)|round(2) }}%</p>
        <p>链: {{ blockchain_info.chain }}</p>
    </div>

    <div class="block-list">
        <h2>最近区块</h2>
        <table>
            <thead>
                <tr>
                    <th>高度</th>
                    <th>哈希</th>
                    <th>时间</th>
                    <th>交易数</th>
                </tr>
            </thead>
            <tbody>
                {% for block in latest_blocks %}
                <tr>
                    <td>{{ block.height }}</td>
                    <td><a href="/block/{{ block.hash }}">{{ block.hash|truncate(20) }}...</a></td>
                    <td>{{ block.time|timestamp_to_date }}</td>
                    <td>{{ block.tx_count }}</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</body>
</html>
