<!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;
        }
        .tx-info {
            background-color: #f9f9f9;
            border-radius: 4px;
            padding: 20px;
            margin-bottom: 20px;
        }
        .vin-list, .vout-list {
            border: 1px solid #ddd;
            border-radius: 4px;
            margin-bottom: 20px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
        }
        th, td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #f2f2f2;
        }
        a {
            color: #0366d6;
            text-decoration: none;
        }
        a:hover {
            text-decoration: underline;
        }
        .info-row {
            display: flex;
            margin-bottom: 10px;
        }
        .info-label {
            font-weight: bold;
            width: 150px;
        }
        .info-value {
            word-break: break-all;
        }
    </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="tx-info">
        <div class="info-row">
            <div class="info-label">交易ID:</div>
            <div class="info-value">{{ tx.txid }}</div>
        </div>
        <div class="info-row">
            <div class="info-label">区块哈希:</div>
            <div class="info-value">
                {% if tx.blockhash %}
                <a href="/block/{{ tx.blockhash }}">{{ tx.blockhash }}</a>
                {% else %}
                未确认
                {% endif %}
            </div>
        </div>
        <div class="info-row">
            <div class="info-label">确认数:</div>
            <div class="info-value">{{ tx.confirmations if tx.confirmations is defined else 0 }}</div>
        </div>
        <div class="info-row">
            <div class="info-label">时间:</div>
            <div class="info-value">{{ tx.time|timestamp_to_date if tx.time is defined else '未确认' }}</div>
        </div>
        <div class="info-row">
            <div class="info-label">大小:</div>
            <div class="info-value">{{ tx.size }} 字节</div>
        </div>
        <div class="info-row">
            <div class="info-label">权重:</div>
            <div class="info-value">{{ tx.weight }}</div>
        </div>
        <div class="info-row">
            <div class="info-label">版本:</div>
            <div class="info-value">{{ tx.version }}</div>
        </div>
        <div class="info-row">
            <div class="info-label">锁定时间:</div>
            <div class="info-value">{{ tx.locktime }}</div>
        </div>
    </div>

    <div class="vin-list">
        <h2>输入 ({{ tx.vin|length }})</h2>
        <table>
            <thead>
                <tr>
                    <th>序号</th>
                    <th>前置交易ID</th>
                    <th>索引</th>
                    <th>脚本</th>
                </tr>
            </thead>
            <tbody>
                {% for vin in tx.vin %}
                <tr>
                    <td>{{ loop.index0 }}</td>
                    <td>
                        {% if vin.txid is defined %}
                        <a href="/tx/{{ vin.txid }}">{{ vin.txid }}</a>
                        {% else %}
                        Coinbase
                        {% endif %}
                    </td>
                    <td>{{ vin.vout if vin.vout is defined else 'N/A' }}</td>
                    <td>
                        {% if vin.scriptSig is defined %}
                        {{ vin.scriptSig.asm|truncate(50) }}...
                        {% elif vin.coinbase is defined %}
                        {{ vin.coinbase|truncate(50) }}...
                        {% else %}
                        N/A
                        {% endif %}
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

    <div class="vout-list">
        <h2>输出 ({{ tx.vout|length }})</h2>
        <table>
            <thead>
                <tr>
                    <th>序号</th>
                    <th>金额 (BTC)</th>
                    <th>地址</th>
                    <th>类型</th>
                </tr>
            </thead>
            <tbody>
                {% for vout in tx.vout %}
                <tr>
                    <td>{{ vout.n }}</td>
                    <td>{{ vout.value }}</td>
                    <td>
                        {% if vout.scriptPubKey.addresses is defined %}
                        {% for address in vout.scriptPubKey.addresses %}
                        {{ address }}<br>
                        {% endfor %}
                        {% else %}
                        无标准地址
                        {% endif %}
                    </td>
                    <td>{{ vout.scriptPubKey.type }}</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
    
    <p><a href="/">返回首页</a></p>
</body>
</html>
