<!doctype html>
<html lang="ko">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Transaction - <%= service.name %></title>
    <link rel="stylesheet" href="/css/admin.css">
  </head>
  <body>
    <main class="shell explorer-shell explorer-wide">
      <header class="topbar explorer-topbar">
        <div><p class="eyebrow"><%= service.mode %></p><h1>Transaction Detail</h1></div>
        <div class="top-actions"><a class="nav-button subtle" href="https://aisfor.kr/chain-wallet?next=/wallet">Wallet</a><a class="nav-button subtle" href="/explorer">Explorer</a><a class="nav-button subtle" href="/admin">Admin</a></div>
      </header>
      <% if (!tx) { %>
        <section class="panel"><h2>Transaction not found</h2><p class="empty">요청한 transaction을 찾을 수 없습니다.</p></section>
      <% } else { %>
        <section class="panel explorer-detail-hero">
          <div>
            <p class="eyebrow"><%= txKind %> transaction</p>
            <h2><%= tx.type || tx.actionType || 'Transaction' %></h2>
            <code class="hash-block"><%= tx.txHash || tx.id %></code>
          </div>
          <div class="detail-status-stack">
            <span class="badge badge-ok"><%= tx.status || '-' %></span>
            <% if (tx.ledgerBlockHeight) { %><a class="nav-button" href="/explorer/block/<%= encodeURIComponent(tx.ledgerBlockHeight) %>">Ledger Block #<%= tx.ledgerBlockHeight %></a><% } %>
          </div>
        </section>
        <section class="grid detail-grid">
          <article class="panel">
            <div class="panel-title"><h2>Transfer</h2><span>value</span></div>
            <div class="stat-list compact">
              <div class="stat-row"><span>Amount</span><strong><%= toDisplayAmount(tx.amount) %> <%= tx.symbol || '' %></strong></div>
              <div class="stat-row"><span>Fee</span><strong><%= toDisplayAmount(tx.fee || 0) %> <%= tx.symbol || '' %></strong></div>
              <div class="stat-row"><span>Nonce</span><strong><%= tx.nonce || '-' %></strong></div>
              <div class="stat-row"><span>Created</span><strong><%= tx.createdAt || '-' %></strong></div>
              <div class="stat-row"><span>Confirmed</span><strong><%= tx.confirmedAt || '-' %></strong></div>
            </div>
          </article>
          <article class="panel">
            <div class="panel-title"><h2>Participants</h2><span>address / actor</span></div>
            <div class="stat-list compact">
              <div class="stat-row"><span>From</span><code><%= tx.fromAddress || tx.actorId || 'GENESIS' %></code></div>
              <div class="stat-row"><span>To</span><code><%= tx.toAddress || tx.targetId || '-' %></code></div>
              <div class="stat-row"><span>Ledger Block</span><strong><%= tx.ledgerBlockHeight ? ('#' + tx.ledgerBlockHeight) : '-' %></strong></div>
              <div class="stat-row"><span>Ledger Hash</span><code><%= tx.ledgerBlockHash || '-' %></code></div>
              <div class="stat-row"><span>Mock Tx Block</span><strong><%= tx.chainMockBlockHeight || tx.blockHeight || '-' %></strong></div>
              <div class="stat-row"><span>Chain Tx</span><code><%= tx.chainTxHash || tx.txHash || '-' %></code></div>
              <div class="stat-row"><span>Metadata</span><code><%= tx.metadata ? JSON.stringify(tx.metadata) : '-' %></code></div>
            </div>
          </article>
        </section>
        <% if (reviewDecision) { %>
          <section class="panel">
            <div class="panel-title"><h2>Review Decision Trace</h2><span><%= reviewDecision.decision %></span></div>
            <div class="chain-strip">
              <div><span>Decision</span><strong><%= reviewDecision.decision %></strong></div>
              <div><span>Reviewer</span><strong><%= reviewDecision.reviewer || '-' %></strong></div>
              <div><span>Reward</span><code><%= shortHash(reviewDecision.rewardId || '-') %></code></div>
              <div><span>Ledger Block</span><strong><%= reviewDecision.chainLedgerBlockHeight ? ('#' + reviewDecision.chainLedgerBlockHeight) : '-' %></strong></div>
            </div>
            <div class="item">
              <strong>Review Decision</strong>
              <a href="/explorer/reward-review/<%= encodeURIComponent(reviewDecision.id) %>"><code><%= reviewDecision.id %></code></a>
            </div>
            <% if (reward) { %>
              <div class="item">
                <strong>Reward Ledger</strong>
                <a href="/explorer/reward/<%= encodeURIComponent(reward.id) %>"><code><%= reward.id %></code></a>
                <span><%= reward.category %> / <%= reward.rewardAmount %> <%= reward.symbol %></span>
              </div>
            <% } %>
            <% if (audit) { %>
              <div class="item">
                <strong>Reward Audit</strong>
                <a href="/explorer/reward-audit/<%= encodeURIComponent(audit.id) %>"><code><%= shortHash(audit.requestHash || audit.id) %></code></a>
                <span><%= audit.validation && audit.validation.ok ? 'validation ok' : 'review' %></span>
              </div>
            <% } %>
            <% if (reviewDecision.chainLedgerBlockHeight) { %>
              <div class="item">
                <strong>Ledger Block Anchor</strong>
                <a href="/explorer/block/<%= encodeURIComponent(reviewDecision.chainLedgerBlockHeight) %>"><code>#<%= reviewDecision.chainLedgerBlockHeight %></code></a>
                <span><%= reviewDecision.chainLedgerBlockHash || '-' %></span>
              </div>
            <% } %>
          </section>
        <% } %>
      <% } %>
    </main>
  </body>
</html>
