<% if @officer_assignments.any? %>
  <h2><%= t("officing.results.new.title", poll: @poll.name) %></h2>
  <%= render Officing::Results::FormComponent.new(@poll, @officer_assignments) %>
<% else %>
  <h2><%= @poll.name %></h2>
  <div class="callout alert">
    <%= t("officing.results.new.not_allowed") %>
  </div>
<% end %>

<% if @partial_results.present? %>

  <hr>
  <h3><%= t("officing.results.new.results_list") %></h3>

  <table>
    <thead>
      <th><%= t("officing.results.new.date") %></th>
      <th><%= t("officing.results.new.booth") %></th>
      <th>&nbsp;</th>
    </thead>
    <tbody>
      <% results_by_booth = @partial_results.group_by(&:booth_assignment_id) %>
      <% results_by_booth.keys.each do |booth_assignment| %>
        <% results_by_booth[booth_assignment].group_by(&:date).keys.each do |date| %>
          <tr id="results_<%= booth_assignment %>_<%= date.strftime("%Y%m%d") %>">
            <td>
              <%= l(date, format: :long) %>
            </td>
            <td>
              <%= results_by_booth[booth_assignment].first.booth_assignment.booth.name %>
            </td>
            <td>
              <%= link_to t("officing.results.new.see_results"), officing_poll_results_path(@poll, date: l(date), booth_assignment_id: booth_assignment) %>
            </td>
          </tr>
        <% end %>
      <% end %>
    </tbody>
  </table>

<% end %>
