<h2><%= t("admin.managers.index.title") %></h2>

<%= render 'admin/shared/user_search', url: search_admin_managers_path %>

<div id="managers">
  <% if @managers.any? %>
    <h3 class="margin"><%= page_entries_info @managers %></h3>

    <table>
      <thead>
        <th scope="col"><%= t("admin.managers.index.name") %></th>
        <th scope="col"><%= t("admin.managers.index.email") %></th>
        <th scope="col" class="small-3"><%= t("admin.shared.actions") %></th>
      </thead>
      <tbody>
        <% @managers.each do |manager| %>
          <tr>
            <td>
              <%= manager.name %>
            </td>
            <td>
              <%= manager.email %>
            </td>
            <td>
              <% if manager.persisted? %>
                <%= link_to t('admin.managers.manager.delete'),
                  admin_manager_path(manager),
                  method: :delete,
                  class: "button hollow alert expanded"
                %>
              <% else %>
                <%= link_to t('admin.managers.manager.add'),
                             { controller: "admin/managers",
                               action: :create,
                               user_id: manager.user_id },
                               method: :post,
                               class: "button success expanded" %>
              <% end %>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>

    <%= paginate @managers %>
  <% else %>
    <div class="callout primary">
      <%= t("admin.managers.index.no_managers") %>
    </div>
  <% end %>
</div>
