<h1>Listing Users</h1>

<%= 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 %>

<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 %>
