<% page_title t('titles.organisation'), t('titles.printers'), t('titles.printer_permissions'), @printer.printerDescription %>

<div class="formContainer">

<h1><%= t('printing_permissions_list.title') %>: <%= html_escape @printer.printerDescription %> (<%= @server.puavoHostname %>)</h1>

<%= Array(@server.puavoSchool).count > 0 ?
    t('printing_permissions_list.available_at_schools') :
    t('printing_permissions_list.not_available_at_schools') %>
<% Array(@server.puavoSchool).each do |s| %>
    <% school = School.find(s) %>
    <%= link_to school.displayName, edit_printer_permission_path(school, @printer) %>
<% end %>

<%= form_for(@printer, url: printer_path(@printer)) do |f| %>
  <h3><%= t('printing_permissions_list.by_schools') %></h3>

  <ul>
    <% if @schools.nil? || @schools.empty? %>
      <li><%= t('printing_permissions_list.none') %></li>
    <% else %>
    <% @schools.each do |school| %>
      <li>
        <%= link_to school.displayName, edit_printer_permission_path(school, @printer) %>
      </li>
    <% end %>
    <% end %>
  </ul>

  <h3><%= t('printing_permissions_list.by_wireless') %></h3>

  <ul>
    <% if @schools_by_wireless.nil? || @schools_by_wireless.empty? %>
      <li><%= t('printing_permissions_list.none') %></li>
    <% else %>
    <% @schools_by_wireless.each do |school| %>
      <li>
        <%= link_to school.displayName, edit_printer_permission_path(school, @printer) %>
      </li>
    <% end %>
    <% end %>
  </ul>

  <h3><%= t('printing_permissions_list.by_groups') %></h3>

  <ul>
    <% if @schools_by_groups.nil? || @schools_by_groups.empty? %>
      <li><%= t('printing_permissions_list.none') %></li>
    <% else %>
    <% @schools_by_groups.each do |(group, school)| %>
      <li>
        <%= group.displayName %>
        <em><%= t('printing_permissions_list.where') %></em>
        <%= link_to school.displayName, edit_printer_permission_path(school, @printer) %>
      </li>
    <% end %>
    <% end %>
  </ul>

  <h3><%= t('printing_permissions_list.by_devices') %></h3>

  <ul>
    <% if @schools_by_devices.nil? || @schools_by_devices.empty? %>
      <li><%= t('printing_permissions_list.none') %></li>
    <% else %>
    <% @schools_by_devices.each do |(device, school)| %>
      <li>
        <%= link_to device.puavoHostname, edit_device_path(school, device) %>
        <em><%= t('printing_permissions_list.where') %></em>
        <%= link_to school.displayName, edit_printer_permission_path(school, @printer) %>
      </li>
    <% end %>
    <% end %>
  </ul>
<% end %>

<%= link_to t('link.back'), printers_path, class: 'btn' %>

</div>
