@page "/"
@page "/invoices"
@using Server.Data
@using Server.Model
@rendermode InteractiveServer

<h3>Rechnungen (@((Invoices ?? []).Count))</h3>

<a href="/create" class="btn btn-primary">Neue Rechnung</a>
<hr />
<div class="row">
@foreach (var invoice in Invoices ?? [])
{
    <div class="col-md-auto pt-3">
      <div class="card" style="width: 18rem;">
        <div class="card-body">
          <h5 class="card-title">#@invoice.InvoiceId</h5>
          <h6 class="card-subtitle mb-2 text-muted">@invoice.IssueDate.ToShortDateString()</h6>
          <p class="card-text">
            @invoice.Customer?.Name<br />
            @invoice.Items.Count Artikel<br />
            @if (SettingsData.Instance.Kleinunternehmer)
            {
              @($"{invoice.TotalNetto:N2} €")<br />
            }
            else
            {
              <div>
                @($"{invoice.TotalNetto:N2} €") Netto<br />
                @($"{invoice.TotalBrutto:N2} €") Brutto<br />
              </div>
            }
            
          </p>
          <a href="@($"edit/{invoice.InvoiceId}")" class="btn btn-sm btn-primary">Bearbeiten</a>
          <button class="btn btn-sm btn-info" @onclick="() => GenerateDocumentAsync(invoice)"><i class="fas fa-file-pdf"></i></button>
          @if (invoice.DeletionAllowed)
          {
            <button class="btn btn-sm btn-danger" style="margin-left: .5rem;" @onclick="() => DeleteInvoiceAsync(invoice.InvoiceId)"><i class="fas fa-trash"></i></button>
          }
        </div>
      </div>
    </div>
}
</div>