<% page_title t('titles.organisation'), t('titles.admins') %>

<h1><%= t('.title') %></h1>

<p><%= t('.description') %></p>

<table class="list">
<tr>
  <th><%= t('.name') %></th>
  <th><%= t('.schools') %></th>
  <th><%= t('users.show.admin_permissions.title') %></th>
</tr>

<% @all_admins.each do |a| %>
<tr>
  <td>
    <%= link_to "#{a[:user].displayName} (#{a[:user].uid})", user_path(a[:user].primary_school, a[:user]) %>
    <% if @current_owners.include?(a[:user].dn.to_s) %>
    <br><span class="adminOrOwner">(<%= t('organisation_owner_role') %>)</span>
    <% end %>
  </td>
  <td>
    <ul class="no-list-bullets margin-0 padding-0">
    <% a[:schools].each do |s| %>
      <%
      parts = []
      parts << '<span class="adminOrOwner">' + t('.admin') + '</span>' if a[:admin_in].include?(s.id.to_i)
      parts << t('users.show.primary_school') if s.dn == a[:pri_school]
      %>
      <li><%= link_to(s.displayName, school_path(s)) %> <%= parts.join(' ').html_safe %></li>
    <% end %>
    </ul>
  </td>
  <td>
    <% unless a[:permissions].empty? %>
    <ul class="no-list-bullets margin-0 padding-0">
    <% a[:permissions].each do |p| %>
      <li><%= t("users.show.admin_permissions.#{p}") %></li>
    <% end %>
    </ul>
    <% end %>
  </td>
</tr>
<% end %>

</table>

<hr>
