<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<% sidebar_weighting ||= nil %>
<% groups = sidebar_weighting || @context.assignment_groups.active %>
<div role="complementary" aria-label="<%= t('Assignment Weights') %>">
<% if @context.group_weighting_scheme == "percent" %>
  <h2><%= before_label 'assignments_weighting', 'Assignments are weighted by group' %></h2>

  <table class="summary">
    <thead>
    <tr>
      <th scope='col'><%= t('headings.group', %{Group}) %></th>
      <th scope='col'><%= t('headings.weight', %{Weight}) %></th>
    </tr>
    </thead>
    <tbody>
    <% if groups.empty? %>
      <tr>
        <th scope='row' colspan="2"><%= t('no_groups', %{No Groups Set Up}) %></th>
      </tr>
    <% else %>
      <% tally = 0 %>
      <% groups.each do |group| %>
        <tr>
          <th scope='row'><%= group.name || t('default_name', "Group") %></th>
          <td><%= group.group_weight ? n(group.group_weight, percentage: true) : t('none') %></td>
          <% tally += group.group_weight || 0 %>
        </tr>
      <% end %>
      <tr style="font-weight: bold;">
        <th scope='row'><%= t('headings.total', %{Total}) %></th>
        <td><%= n(tally, percentage: true) %></td>
      </tr>
    <% end %>
    </tbody>
  </table>
<% else %>
  <h2><%= t('not_weighted', 'Course assignments are not weighted.') %></h2>
<% end %>
</div>
