<!doctype html>
<html lang="<%= lang %>">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><%= wallet ? wallet.address : text.detailText.addressNotFound %> - <%= service.name %></title>
    <link rel="stylesheet" href="/css/admin.css">
  </head>
  <body>
    <main class="shell explorer-shell explorer-wide">
      <%
        const d = text.detailText;
        const tt = text.transferText;
        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.addressDetail %></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 (!wallet) { %>
        <section class="panel"><h2><%= d.addressNotFound %></h2><p class="empty"><%= d.addressNotFoundDesc %></p></section>
      <% } else { %>
        <section class="panel explorer-detail-hero">
          <div>
            <p class="eyebrow"><%= wallet.ownerType %></p>
            <h2><%= wallet.label %></h2>
            <code class="hash-block"><%= wallet.address %></code>
          </div>
          <div class="detail-status-stack"><span class="badge badge-ok"><%= wallet.status %></span><strong><%= toDisplayAmount(wallet.balance) %> <%= displayCoinSymbol(walletStats.coin.symbol) %></strong></div>
        </section>
        <section class="grid metrics explorer-metrics">
          <article><strong><%= toDisplayAmount(wallet.balance) %></strong><span><%= d.balance %></span></article>
          <article><strong><%= toDisplayAmount((wallet.balance || 0) - (wallet.lockedBalance || 0)) %></strong><span><%= d.available %></span></article>
          <article><strong><%= toDisplayAmount(wallet.lockedBalance || 0) %></strong><span><%= d.locked %></span></article>
          <article><strong><%= toDisplayAmount(wallet.rewardBalance || 0) %></strong><span><%= d.rewards %></span></article>
          <article><strong><%= wallet.nonce || 0 %></strong><span><%= d.nonce %></span></article>
          <article><strong><%= transactions.length %></strong><span><%= d.transactions %></span></article>
        </section>
        <section class="panel">
          <div class="panel-title"><h2><%= d.transactions %></h2><span><%= transactions.length %> <%= d.rows %></span></div>
          <div class="table-wrap">
            <table>
              <thead><tr><th><%= tt.time %></th><th><%= tt.type %></th><th><%= tt.from %></th><th><%= tt.to %></th><th><%= tt.amount %></th><th><%= tt.status %></th><th><%= tt.hash %></th></tr></thead>
              <tbody>
                <% if (transactions.length === 0) { %><tr><td colspan="7"><%= d.noWalletTx %></td></tr><% } %>
                <% transactions.forEach(function(tx) { %>
                  <tr>
                    <td><%= tx.confirmedAt || tx.createdAt || '-' %></td>
                    <td><%= tx.type %></td>
                    <td><code><%= shortHash(tx.fromAddress || 'GENESIS') %></code></td>
                    <td><code><%= shortHash(tx.toAddress || '-') %></code></td>
                    <td><strong><%= toDisplayAmount(tx.amount) %> <%= displayCoinSymbol(tx.symbol) %></strong></td>
                    <td><span class="badge badge-ok"><%= tx.status %></span></td>
                    <td><a href="<%= urlWithLang('/explorer/tx/' + encodeURIComponent(tx.txHash)) %>"><code><%= shortHash(tx.txHash) %></code></a></td>
                  </tr>
                <% }) %>
              </tbody>
            </table>
          </div>
        </section>
      <% } %>
    </main>
  </body>
</html>
