- content_for :title
  = t '.vote_results'

.row
  .col-lg-12
    h1.page-header
      = t '.vote_results'
      - if @conference.has_vote_results?
        small<
          = t '.vote_data_updated_at', updated_at: l(@conference.vote_data_updated_at, format: :long)
- if @conference.vote_data_endpoint.present?
  .row
    .col-lg-12
      .panel.panel-default
        table.table.table-striped.table-hover.record-table
          - if @conference.has_vote_results?
            thead
              tr
                th.text-right = t('.rank')
                th = Event.model_name.human.mb_chars.capitalize
                th = Event.human_attribute_name :status
                th
          tbody
            - if @conference.has_vote_results?
              - current_conference.events.order(rank: :asc).group_by(&:rank).each do |rank, events|
                - events.each.with_index do |event, index|
                  tr
                    - if index == 0
                      - if event.ranked?
                        td.text-center rowspan="#{events.count}"
                          .large
                            span.label.label-info = event.rank
                          span title="#{t('.vote_ratio', votes: event.number_of_votes, total_votes: @conference.number_of_ballots_cast)}"
                            = number_to_percentage(event.per_cent_of_votes, strip_insignificant_zeros: true, precision: 2)
                      - else
                        td.text-center rowspan="#{events.count}"
                          .large
                            span.label.label-danger &times;
                          = t('.unranked')
                    td
                      h4 = event.title
                      h5 = event.subtitle
                      = links_to_event_participants_for(event)
                    td
                      span class="label label-lg label-#{proposition_status_class(event.status)}"
                        = icon(proposition_status_glyph(event.status), t("activerecord.attributes.proposition.statuses.#{event.status}"))
                    td.actions = action_buttons(@conference, event, [:show])
            - else
              tr
                td.text-center colspan="20"
                  p.large
                    = t '.vote_data_never_updated'
                  p
                    =< link_to update_vote_data_management_conference_path, method: :patch, class: ['btn', 'btn-primary'] do
                      = icon :refresh, t('.fetch_vote_results')
        - if @conference.has_vote_results?
          .panel-footer.text-right
            .btn-group
              = link_to management_conference_path, class: ['btn', 'btn-info'] do
                = icon :users, t('.back_to', conference: @conference.title)
              = link_to update_vote_data_management_conference_path, method: :patch, class: ['btn', 'btn-primary'] do
                = icon :refresh, t('.fetch_vote_results')
              = link_to management_conference_events_path(current_conference, format: 'csv'), class: 'btn btn-info'
                = icon :download, t('.export')