<!doctype html>
<html lang="<%= lang %>">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><%= text.detailText.transaction %> - <%= service.name %></title>
    <link rel="stylesheet" href="/css/admin.css">
  </head>
  <body>
    <main class="shell explorer-shell explorer-wide">
      <%
        const d = text.detailText;
        function displayCoinSymbol(symbol) {
          const raw = String(symbol || '').trim();
          const upper = raw.toUpperCase();
          if (upper === 'AIS' || upper === 'PLAI' || upper === 'PLAIS') return 'plais';
          return raw || 'plais';
        }
      %>
      <header class="topbar explorer-topbar">
        <div><p class="eyebrow"><%= text.networkLabel %></p><h1><%= d.txDetail %></h1></div>
        <div class="top-actions"><a class="nav-button subtle" href="https://aisfor.kr/chain-wallet?next=/wallet/evm">EVM Wallet</a><a class="nav-button subtle" href="<%= urlWithLang('/explorer') %>">Explorer</a><a class="nav-button subtle" href="<%= urlWithLang('/admin') %>"><%= text.admin %></a></div>
      </header>
      <% if (!tx) { %>
        <section class="panel"><h2><%= d.txNotFound %></h2><p class="empty"><%= d.txNotFoundDesc %></p></section>
      <% } else { %>
        <section class="panel explorer-detail-hero">
          <div>
            <p class="eyebrow"><%= txKind %> transaction</p>
            <h2><%= tx.type || tx.actionType || d.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="<%= urlWithLang('/explorer/legacy/block/' + encodeURIComponent(tx.ledgerBlockHeight)) %>"><%= d.legacyBlock %> #<%= tx.ledgerBlockHeight %></a><% } %>
          </div>
        </section>
        <section class="grid detail-grid">
          <article class="panel">
            <div class="panel-title"><h2><%= d.transfer %></h2><span><%= d.value %></span></div>
            <div class="stat-list compact">
              <div class="stat-row"><span><%= text.transferText.amount %></span><strong><%= toDisplayAmount(tx.amount) %> <%= displayCoinSymbol(tx.symbol) %></strong></div>
              <div class="stat-row"><span><%= d.fee %></span><strong><%= toDisplayAmount(tx.fee || 0) %> <%= displayCoinSymbol(tx.symbol) %></strong></div>
              <div class="stat-row"><span><%= d.nonce %></span><strong><%= tx.nonce || '-' %></strong></div>
              <div class="stat-row"><span><%= d.created %></span><strong><%= tx.createdAt || '-' %></strong></div>
              <div class="stat-row"><span><%= d.confirmed %></span><strong><%= tx.confirmedAt || '-' %></strong></div>
            </div>
          </article>
          <article class="panel">
            <div class="panel-title"><h2><%= d.participants %></h2><span><%= d.addressActor %></span></div>
            <div class="stat-list compact">
              <div class="stat-row"><span><%= text.transferText.from %></span><code><%= tx.fromAddress || tx.actorId || 'GENESIS' %></code></div>
              <div class="stat-row"><span><%= text.transferText.to %></span><code><%= tx.toAddress || tx.targetId || '-' %></code></div>
              <div class="stat-row"><span><%= d.ledgerBlock %></span><strong><%= tx.ledgerBlockHeight ? ('#' + tx.ledgerBlockHeight) : '-' %></strong></div>
              <div class="stat-row"><span><%= d.ledgerHash %></span><code><%= tx.ledgerBlockHash || '-' %></code></div>
              <div class="stat-row"><span><%= d.mockTxBlock %></span><strong><%= tx.chainMockBlockHeight || tx.blockHeight || '-' %></strong></div>
              <div class="stat-row"><span><%= d.chainTx %></span><code><%= tx.chainTxHash || tx.txHash || '-' %></code></div>
              <div class="stat-row"><span><%= d.metadata %></span><code><%= tx.metadata ? JSON.stringify(tx.metadata) : '-' %></code></div>
            </div>
          </article>
        </section>
        <% if (reviewDecision) { %>
          <section class="panel">
            <div class="panel-title"><h2><%= d.reviewDecisionTrace %></h2><span><%= reviewDecision.decision %></span></div>
            <div class="chain-strip">
              <div><span><%= d.decision %></span><strong><%= reviewDecision.decision %></strong></div>
              <div><span><%= d.reviewer %></span><strong><%= reviewDecision.reviewer || '-' %></strong></div>
              <div><span><%= d.reward %></span><code><%= shortHash(reviewDecision.rewardId || '-') %></code></div>
              <div><span><%= d.ledgerBlock %></span><strong><%= reviewDecision.chainLedgerBlockHeight ? ('#' + reviewDecision.chainLedgerBlockHeight) : '-' %></strong></div>
            </div>
            <div class="item">
              <strong><%= d.reviewDecisionTrace %></strong>
              <a href="<%= urlWithLang('/explorer/reward-review/' + encodeURIComponent(reviewDecision.id)) %>"><code><%= reviewDecision.id %></code></a>
            </div>
            <% if (reward) { %>
              <div class="item">
                <strong><%= d.rewardLedger %></strong>
                <a href="<%= urlWithLang('/explorer/reward/' + encodeURIComponent(reward.id)) %>"><code><%= reward.id %></code></a>
                <span><%= reward.category %> / <%= reward.rewardAmount %> <%= displayCoinSymbol(reward.symbol) %></span>
              </div>
            <% } %>
            <% if (audit) { %>
              <div class="item">
                <strong><%= d.rewardAudit %></strong>
                <a href="<%= urlWithLang('/explorer/reward-audit/' + encodeURIComponent(audit.id)) %>"><code><%= shortHash(audit.requestHash || audit.id) %></code></a>
                <span><%= audit.validation && audit.validation.ok ? d.validationOk : d.review %></span>
              </div>
            <% } %>
            <% if (reviewDecision.chainLedgerBlockHeight) { %>
              <div class="item">
                <strong><%= d.ledgerBlockAnchor %></strong>
                <a href="<%= urlWithLang('/explorer/legacy/block/' + encodeURIComponent(reviewDecision.chainLedgerBlockHeight)) %>"><code>#<%= reviewDecision.chainLedgerBlockHeight %></code></a>
                <span><%= reviewDecision.chainLedgerBlockHash || '-' %></span>
              </div>
            <% } %>
          </section>
        <% } %>
      <% } %>
    </main>
  </body>
</html>
