<%= render HeaderComponent.new(title: "Invitations") %>

<%= render MainSimpleComponent.new do %>
  <section>
    <%= render QuickstatsContainerComponent.new do %>
      <%= render QuickstatsItemComponent.new(
          type: :number,
          title: 'Available',
          value: @stats[:available],
      ) %>
      <%= render QuickstatsItemComponent.new(
          type: :number,
          title: 'Accepted',
          value: @stats[:accepted],
      ) %>
      <%= render QuickstatsItemComponent.new(
          type: :number,
          title: 'Users with referrals',
          value: @stats[:users_with_referrals],
          meta: "/ #{User.count}"
      ) %>
    <% end %>
  </section>
  <% if @invitations_used.any? %>
    <section>
      <h3>Recently Accepted</h3>
      <table class="divided mb-8">
        <thead>
          <tr>
            <th>Token</th>
            <th>Accepted</th>
            <th>Inviter</th>
            <th>Invited user</th>
          </tr>
        </thead>
        <tbody>
          <% @invitations_used.each do |invitation| %>
            <tr>
              <td class="overflow-ellipsis font-mono"><%= invitation.token %></td>
              <td><%= invitation.used_at.strftime("%Y-%m-%d (%H:%M UTC)") %></td>
              <td><%= link_to invitation.user.address, admin_user_path(invitation.user.address), class: "ks-text-link" %></td>
              <td><%= link_to invitation.invitee.address, admin_user_path(invitation.invitee.address), class: "ks-text-link" %></td>
            </tr>
          <% end %>
        </tbody>
      </table>
      <%== pagy_nav @pagy %>
    </section>
  <% end %>
<% end %>
