<section class="viewblock">
  <header class="viewblock-header">
    <div class="viewblock-header_right">
      <div class="button-padding">
        <% if can? :create, User %>
          <%= link_to t(:new_model, model: User.model_name.human), new_user_path, class: "btn" %>
        <% end %>
      </div>
    </div>
    <h1 class="default-padding">
      <%= t(:all_model, model: User.model_name.human(count: 42)) %>
    </h1>
  </header>
  <div class="viewblock-cont">
    <table>
      <tr>
        <th><%= t '.name' %></th>
        <th><%= User.human_attribute_name(:email) %></th>
        <th><%= User.human_attribute_name(:groups) %></th>
        <th><%= t 'actions' %></th>
      </tr>

      <% @users.each do |user| %>
        <tr>
          <td>
            <% if can? :read, User %>
              <%= link_to user.name, user %>
            <% else %>
              <%= user.name %>
            <% end %>
          </td>
          <td><%= user.email %></td>
          <td><%= user.groups.map(&:name).join(",") %></td>

          <td>
            <% if can? :edit, user %>
              <%= link_to t(:edit, model: User.model_name.human), edit_user_path(user), class: "btn" %>
            <% end %>
            <% if can? :delete, user %>
              <% if user.is_deletable? %>
                <%= link_to t(:destroy, model: User.model_name.human), user,
                            data: { confirm: t(:are_you_sure_delete_model_key, model: User.model_name.human, key: user.name) }, method: :delete, class: "btn" %>
              <% else %>
                <%= link_to t(:destroy, model: User.model_name.human), '#', class: "btn disabled tooltip-basic", 'data-tooltip-text' => t(:user_not_deletable, model: User.model_name.human, key: user.name) %>
              <% end %>
            <% end %>
          </td>
        </tr>
      <% end %>
    </table>

    <div class="pagination-cont default-padding" style="padding-top: 0px; padding-bottom: 0px;">
      <%= paginate @users %>
    </div>
  </div>

</section>
