<!doctype html>
<html lang="ko">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><%= service.name %> Reward Review</title>
    <link rel="stylesheet" href="/css/admin.css">
  </head>
  <body>
    <main class="shell explorer-shell">
      <header class="topbar">
        <div>
          <p class="eyebrow"><%= service.mode %></p>
          <h1>Reward Review Decision</h1>
        </div>
        <div class="top-actions">
          <a class="nav-button subtle" href="/explorer">Explorer</a>
          <a class="nav-button subtle" href="/admin/rewards">Rewards</a>
          <a class="nav-button subtle" href="/admin">Admin</a>
        </div>
      </header>

      <% if (!reviewDecision) { %>
        <section class="panel">
          <div class="panel-title"><h2>Review Decision Not Found</h2><span>missing</span></div>
          <p class="empty">No reward review decision matched this id or reward id.</p>
        </section>
      <% } else { %>
        <section class="panel">
          <div class="panel-title">
            <h2><%= reviewDecision.decision %> / <%= reviewDecision.reviewer || 'operator' %></h2>
            <span>operator trace</span>
          </div>
          <div class="chain-strip">
            <div><span>Reward</span><code><%= shortHash(reviewDecision.rewardId || '-') %></code></div>
            <div><span>Previous Amount</span><strong><%= reviewDecision.previousRewardAmount || 0 %></strong></div>
            <div><span>Reviewed</span><strong><%= reviewDecision.reviewedAt || reviewDecision.createdAt || '-' %></strong></div>
            <div><span>Flags</span><strong><%= (reviewDecision.flags || []).length %></strong></div>
            <div><span>Chain Status</span><strong><%= reviewDecision.chainStatus || '-' %></strong></div>
            <div><span>Ledger Block</span><strong><%= reviewDecision.chainLedgerBlockHeight ? ('#' + reviewDecision.chainLedgerBlockHeight) : '-' %></strong></div>
            <div><span>Mock Tx Block</span><strong><%= reviewDecision.chainMockBlockHeight || '-' %></strong></div>
          </div>
          <div class="item">
            <strong>Decision ID</strong>
            <code><%= reviewDecision.id %></code>
          </div>
          <div class="item">
            <strong>Reason</strong>
            <span><%= reviewDecision.reason || '-' %></span>
          </div>
          <div class="item">
            <strong>Review Chain Transaction</strong>
            <% if (reviewDecisionTx) { %>
              <a href="/explorer/tx/<%= encodeURIComponent(reviewDecisionTx.txHash || reviewDecisionTx.id) %>"><code><%= reviewDecisionTx.txHash || reviewDecisionTx.id %></code></a>
              <span><%= reviewDecisionTx.status || '-' %> / ledger block <%= reviewDecisionTx.ledgerBlockHeight || reviewDecisionTx.blockHeight || '-' %></span>
            <% } else { %>
              <code><%= reviewDecision.txHash || reviewDecision.chainTransactionId || '-' %></code>
            <% } %>
          </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>

        <section class="grid">
          <article class="panel">
            <div class="panel-title"><h2>Reward Link</h2><span>ledger</span></div>
            <% if (reward) { %>
              <div class="item">
                <strong><%= reward.category %> / <%= reward.rewardAmount %> <%= reward.symbol %></strong>
                <span><%= reward.sourceService %> / <%= reward.actionType %></span>
                <a href="/explorer/reward/<%= encodeURIComponent(reward.id) %>"><code><%= reward.id %></code></a>
              </div>
            <% } else { %>
              <p class="empty">The linked reward entry is not available.</p>
            <% } %>
          </article>

          <article class="panel">
            <div class="panel-title"><h2>Audit Link</h2><span>request trace</span></div>
            <% if (audit) { %>
              <div class="item">
                <strong><%= audit.sourceService %> / <%= audit.actionType %> / <%= audit.status %></strong>
                <span><%= audit.validation && audit.validation.ok ? 'validation ok' : 'review' %></span>
                <a href="/explorer/reward-audit/<%= encodeURIComponent(audit.id) %>"><code><%= shortHash(audit.requestHash || audit.id) %></code></a>
              </div>
            <% } else { %>
              <p class="empty">No reward audit log is linked to this decision.</p>
            <% } %>
          </article>
        </section>

        <section class="panel">
          <div class="panel-title"><h2>Flags At Review</h2><span><%= (reviewDecision.flags || []).length %></span></div>
          <% if (!(reviewDecision.flags || []).length) { %><p class="empty">No flags were present when this decision was recorded.</p><% } %>
          <% (reviewDecision.flags || []).forEach(function(flag) { %>
            <div class="item"><strong><%= flag %></strong></div>
          <% }) %>
        </section>
      <% } %>
    </main>
  </body>
</html>
