<%- include('../partials/header') %>

<%
function fmtDateRo(v) {
  if (!v) return '-';
  const d = new Date(v);
  if (isNaN(d.getTime())) return v;
  const p = n => String(n).padStart(2,'0');
  return `${p(d.getDate())}.${p(d.getMonth()+1)}.${d.getFullYear()} ${p(d.getHours())}:${p(d.getMinutes())}`;
}
%>


<div class="grid two">
<div class="card">
  <h2>Comanda <%= order.external_id %></h2>
  <p><strong>Client:</strong> <%= order.customer_name || '-' %></p>
  <p><strong>Tip:</strong> <%= order.customer_type || 'NECUNOSCUT' %></p>
  <% if (order.customer_type==='PJ' || order.company_name || order.cui) { %>
    <p><strong>Firmă:</strong> <%= order.company_name || '-' %></p>
    <p><strong>CUI:</strong> <%= order.cui || '-' %></p>
  <% } %>
  <p><strong>Email:</strong> <%= order.email || '-' %></p>
  <p><strong>Telefon:</strong> <%= order.phone || '-' %></p>
  <p><strong>Adresă:</strong> <%= [order.address,order.city,order.county,order.postal_code].filter(Boolean).join(', ') || '-' %></p>
  <p><strong>Data:</strong> <%= fmtDateRo(order.ordered_at) %></p>
  <p><strong>Status:</strong> <%= order.status || '-' %></p>
  <p><strong>Tip plată:</strong> <%= order.payment_method || '-' %></p>
  <p><strong>Status plată:</strong> <%= order.payment_status || '-' %></p>
  <p><strong>Total:</strong> <%= Number(order.total || 0).toFixed(2) %> <%= order.currency %></p>
</div>

<div class="card">
  <h2>Produse cumpărate (<%= items.length %>)</h2>
  <table>
    <thead><tr><th>SKU</th><th>Produs</th><th>Categorie</th><th>Cant.</th><th>Preț</th><th>Total</th></tr></thead>
    <tbody>
    <% items.forEach(i => { %>
      <tr>
        <td><%= i.sku || '-' %></td>
        <td><%= i.product_name || '-' %></td>
        <td><%= i.category || '-' %></td>
        <td><%= i.quantity %></td>
        <td><%= Number(i.unit_price || 0).toFixed(2) %></td>
        <td><%= Number(i.line_total || 0).toFixed(2) %></td>
      </tr>
    <% }) %>
    </tbody>
  </table>
</div>
</div>

<%- include('../partials/footer') %>
