<%# locals: (club:, payments:) %>
<section class="billing-documents" style="margin-top:40px">
  <h2>Pagamenti e fatture</h2>
  <p style="color:#888;font-size:0.9rem">
    Storico dei pagamenti della società e relative fatture emesse da Match Live TV.
  </p>

  <% unless club.billing_profile_complete? %>
    <div class="flash alert" style="margin:16px 0">
      <strong>Dati di fatturazione incompleti.</strong>
      Compila ragione sociale, indirizzo, P.IVA/CF e SDI o PEC per ricevere le fatture via email.
      <%= link_to "Completa ora", public_club_billing_profile_path(club), class: "btn btn-secondary", style: "margin-top:10px;display:inline-block" %>
    </div>
  <% else %>
    <p style="color:#888;font-size:0.88rem">
      Intestatario: <%= club.billing_profile_summary %>
      · <%= link_to "Modifica dati", public_club_billing_profile_path(club) %>
    </p>
  <% end %>

  <h3 style="margin-top:28px;font-size:1.1rem">Pagamenti e fatture</h3>
  <% if payments.any? %>
    <table class="data billing-table">
      <thead>
        <tr>
          <th>Data</th>
          <th>Descrizione</th>
          <th>Importo</th>
          <th>Stato pagamento</th>
          <th>Fattura</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <% payments.each do |payment| %>
          <% inv = payment.invoice_for_display %>
          <tr>
            <td><%= payment.paid_at ? l_local(payment.paid_at, format: :short) : "—" %></td>
            <td><%= payment.display_description %></td>
            <td><%= payment.formatted_amount %></td>
            <td><%= payment.display_status %></td>
            <td>
              <% if inv.present? %>
                <%= inv.display_number %>
                · <%= inv.display_status %>
              <% else %>
                —
              <% end %>
            </td>
            <td>
              <% if inv&.downloadable? %>
                <%= link_to "Scarica PDF", public_club_billing_invoice_path(club, inv) %>
              <% elsif inv&.draft? %>
                <span style="color:#888">PDF in preparazione</span>
              <% else %>
                <span style="color:#888">—</span>
              <% end %>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>
  <% else %>
    <p style="color:#888">Nessun pagamento registrato. Dopo un abbonamento premium comparirà qui.</p>
  <% end %>
</section>
