<div class="container">
  <p id="notice"><%= notice %></p>
  <div class="col-7">
    <div class="welcome">Editors in Chief Dashboard</div>
    <div class="hero-small dashboard">
      <div class="hero-title">
        <%= image_tag "icon_papers.svg", height: "32px" %><h1>Invitations</h1>
      </div>
      <div class="welcome" style="padding-left:20px"><%= "Track: #{@track.name}" if @track.present? %></div>
    </div>
  </div>
</div>

<%= render partial: "aeic_dashboard/menu" %>
<div class="container">
  <% if @invitations.empty? %>
    <div class="generic-content-item">There are <b>no recent invitations</b> to show</div>
  <% else %>
    <table class="dashboard-table sortable">
      <thead>
        <tr class="text-nowrap">
          <th scope="col">Editor</th>
          <th scope="col" class="sorttable_nosort">Paper</th>
          <th scope="col" class="sorttable_nosort">Invitation status</th>
          <th scope="col">Date</th>
          <th scope="col" class="sorttable_nosort">Actions</th>
        </tr>
      </thead>

      <tbody>
        <%- @invitations.each do |invitation| %>
        <tr>
          <td sorttable_customkey=<%= invitation.editor.full_name %>>
            <%= image_tag(avatar(invitation.editor.login), size: "24x24", class: "avatar", title: github_user_link(invitation.editor.login)) %>
            <%= link_to invitation.editor.full_name, invitation.editor, title: "Editor profile" %>
            (<%= link_to "@#{invitation.editor.login}", github_user_link(invitation.editor.login), title: "GitHub profile", target: "_blank" %>)
          </td>
          <td>
            <%= link_to truncate(invitation.paper.title, length: 80), invitation.paper.meta_review_url, title: invitation.paper.title %>
          </td>
          <td><%= invitation_status(invitation) %></td>
          <td sorttable_customkey=<%= invitation.created_at %>>Invited <%= time_ago_in_words(invitation.created_at) %> ago</td>
          <td><%= link_to("Cancel", expire_invitation_path(invitation, page: params[:page], track_id: params[:track_id].presence), data: { turbo_method: :put, turbo_confirm: "Are you sure you want to mark this invitation as expired?" }) if invitation.pending? %></td>
        </tr>
        <%- end %>
      </tbody>
    </table>
    <div class="row">
      <div class="pagination_helper">
        <%== pagy_info(@pagy, item_name: t("invitation", count: @invitations.size)) %>
      </div>
      <%= pagy_pagination @pagy %>
    </div>
  <% end %>
</div>
