<!doctype html>
<html lang="it" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8"/>
  <style>
    @page { size: A4; margin: 18mm 15mm; }
    body { font-family: sans-serif; font-size: 10.5pt; }
    .header { display: flex; justify-content: space-between; }
    .addresses { margin-top: 10mm; display: flex; justify-content: space-between; }
    table { width: 100%; border-collapse: collapse; margin-top: 8mm; }
    th, td { padding: 6px; border-bottom: 1px solid #ccc; }
    th { text-align: left; }
    .totals { margin-top: 6mm; width: 40%; margin-left: auto; }
    .totals td { border: none; }
    .page-break { page-break-before: always; }
  </style>
</head>
<body>

<div class="header">
  <div>
    <div><strong th:text="${sellerDisplayName}">Nome Cognome</strong></div>
    <div th:text="${sellerAddressLine1}">Via Esempio 12</div>
    <div th:text="${sellerAddressLine2}">6500 Bellinzona, CH</div>
    <div th:text="${sellerEmail}">email@example.com</div>
  </div>

  <div>
    <div><strong>Fattura</strong></div>
    <div>Numero: <span th:text="${invoiceNumber}">2026-000123</span></div>
    <div>Data: <span th:text="${invoiceDate}">2026-02-13</span></div>
    <div>Scadenza: <span th:text="${dueDate}">2026-02-20</span></div>
  </div>
</div>

<div class="addresses">
  <div>
    <div><strong>Fatturare a</strong></div>
    <div th:text="${buyerDisplayName}">Cliente SA</div>
    <div th:text="${buyerAddressLine1}">Via Cliente 7</div>
    <div th:text="${buyerAddressLine2}">8000 Zürich, CH</div>
  </div>
</div>

<table>
  <thead>
    <tr>
      <th>Descrizione</th>
      <th style="text-align:right;">Qtà</th>
      <th style="text-align:right;">Prezzo</th>
      <th style="text-align:right;">Totale</th>
    </tr>
  </thead>
  <tbody>
    <tr th:each="lineItem : ${invoiceLineItems}">
      <td th:text="${lineItem.description}">Stampa 3D pezzo X</td>
      <td style="text-align:right;" th:text="${lineItem.quantity}">1</td>
      <td style="text-align:right;" th:text="${lineItem.unitPriceFormatted}">CHF 10.00</td>
      <td style="text-align:right;" th:text="${lineItem.lineTotalFormatted}">CHF 10.00</td>
    </tr>
  </tbody>
</table>

<table class="totals">
  <tr>
    <td>Subtotale</td>
    <td style="text-align:right;" th:text="${subtotalFormatted}">CHF 10.00</td>
  </tr>
  <tr>
    <td><strong>Totale</strong></td>
    <td style="text-align:right;"><strong th:text="${grandTotalFormatted}">CHF 10.00</strong></td>
  </tr>
</table>

<div style="margin-top:6mm;" th:text="${paymentTermsText}">
  Pagamento entro 7 giorni. Grazie.
</div>

<!-- Pagina dedicata alla QR-bill -->
<div class="page-break"></div>
<div th:utext="${qrBillSvg}" style="width: 210mm; height: 105mm; position: absolute; bottom: 0; left: 0;"></div>

</body>
</html>
