<%- include('partials/head') %>
<div class="page-head">
  <div>
    <h1><%= t('dashboard.hello', { name: user.name }) %></h1>
    <p class="muted small"><%= t('dashboard.sub') %></p>
  </div>
  <div class="cta-row">
    <a class="btn btn-ghost" href="/wallet"><%= t('dashboard.topup') %></a>
    <a class="btn btn-primary" href="/services"><%= t('dashboard.order') %></a>
  </div>
</div>

<div class="grid stat-grid">
  <div class="stat">
    <span class="stat-label"><%= t('dashboard.wallet_balance') %></span>
    <span class="stat-value"><%= fmt(user.balance) %></span>
  </div>
  <div class="stat">
    <span class="stat-label"><%= t('dashboard.pending_orders') %></span>
    <span class="stat-value"><%= pending %></span>
  </div>
  <div class="stat">
    <span class="stat-label"><%= t('dashboard.completed_orders') %></span>
    <span class="stat-value"><%= completed %></span>
  </div>
</div>

<div class="panel">
  <div class="panel-head">
    <h2><%= t('dashboard.recent') %></h2>
    <a class="small" href="/orders"><%= t('dashboard.all_orders') %> <%= lang === 'en' ? '→' : '←' %></a>
  </div>
  <% if (!recent.length) { %>
    <div class="empty"><%= t('dashboard.empty') %></div>
  <% } else { %>
    <table class="table">
      <thead>
        <tr>
          <th>#</th><th><%= t('common.service') %></th><th><%= t('common.device') %></th>
          <th><%= t('common.price') %></th><th><%= t('common.status') %></th>
          <th><%= t('dashboard.remaining') %></th><th><%= t('common.date') %></th>
        </tr>
      </thead>
      <tbody>
        <% recent.forEach(function (o) { %>
          <tr>
            <td class="mono"><a href="/orders/<%= o.id %>">#<%= o.id %></a></td>
            <td><%= svcName(o) %></td>
            <td class="mono"><%= o.device_info %></td>
            <td class="price"><%= fmt(o.price) %></td>
            <td>
              <span class="badge badge-<%= o.status %>"><%= STATUS_LABELS[o.status] %></span>
              <% if (o.status === 'completed') { %>
                <div class="result-note"><%= o.result_note || t('orders.result_default') %></div>
              <% } %>
            </td>
            <td>
              <% if (o.status === 'processing' && o.eta_at) { %>
                <span class="countdown" data-countdown="<%= o.eta_at.replace(' ', 'T') %>Z">…</span>
              <% } else if (o.status === 'completed') { %>
                <span class="muted small"><%= t('dashboard.done') %></span>
              <% } else if (o.status === 'rejected') { %>
                <span class="muted small"><%= t('dashboard.refunded') %></span>
              <% } else { %>
                <span class="muted small">—</span>
              <% } %>
            </td>
            <td class="muted small"><%= (o.service_date || o.created_at).slice(0, 16) %></td>
          </tr>
        <% }) %>
      </tbody>
    </table>
  <% } %>
</div>
<%- include('partials/foot') %>
