<h1 class="title">Listing Users</h1>
<p><%= User.lately.count %> players have signed in within the past 30 days.</p>
<% # FIXME: check this %>
<%= link_to 'Show them', params.to_enum.to_h.merge(filter: 'lately'), class: 'button' %><br><br><br>

<p>Search for users by name or Steam ID:</p>

<%= form_tag(users_path, method: 'get', class: 'square search') do %>
  <%= hidden_field_tag :direction, params[:direction] %>
  <%= hidden_field_tag :sort, params[:sort] %>
  <div class="fields query">
    <%= text_field_tag :search, params[:search] %>
  </div>
  <div class="controls">
    <%= submit_tag "Search", name: nil %>
  </div>
<% end %>

<%= will_paginate @users %>

<table id="users" class="striped">
  <tr>
    <th class="country"></th>
    <th class="username">Username</th>
    <th class="name">Name</th>
    <th class="steamid">Steam ID</th>
    <th class="age">Age</th>
    <% if cuser and cuser.admin? %>
      <th class="actions"></th>
    <% end %>
  </tr>

  <% @users.each do |user| %>
    <tr>
      <td><%= flag user.country %></td>
      <td><%= link_to (h user.username), user %></td>
      <td><%= h user.firstname %> <%=h user.lastname %></td>
      <td><%= h user.steamid %></td>
      <td><%= user.age %></td>
      <% if cuser and cuser.admin? %>
        <td class="actions">
          <%= link_to edit_user_path(user) do %>
            <%= icon 'pencil' %>
          <% end %>
          <%= link_to user, confirm: "Proceed to delete?", method: :delete do %>
            <%= icon 'times' %>
          <% end %>
        </td>
      <% end %>
    </tr>
  <% end %>
</table>

<%= will_paginate @users %>