<%
# 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/>.
%>

<% dashboard ||= false %>
<% is_current_term ||= false %>
<% # only show updated css in unpublished, current enrollments with FF enabled %>
<% unpublished_course_redesign =
  (current_enrollment.course.created? || current_enrollment.course.claimed?) &&
  is_current_term &&
  @domain_root_account.feature_enabled?(:unpublished_courses)
%>
<% unless dashboard %>
  <tr class="course-list-table-row <%='course-list-unpublished-course-row' if unpublished_course_redesign %>">
<% end %>
<% if current_enrollment.workflow_state == "invited" && !current_enrollment.inactive? %>
  <div class="<%= dashboard ? 'communication_message dashboard_notification alert alert-info' : 'reminder' %>">
    <h2><a href="<%= course_path(current_enrollment.course_id, :invitation => current_enrollment.uuid) %>"><%= current_enrollment.long_name %></a></h2>
    <div class="body">
      <%=  render :partial => 'shared/invitation', :object => current_enrollment %>
    </div>
  </div>
<% else %>
  <% show_link = [:active, :invited, :accepted, :completed].include?(current_enrollment.state_based_on_date) && (!current_enrollment.course.unpublished? || current_enrollment.admin?) %>
      <% if @show_star_column %>
      <td class="course-list-star-column">
      <% favorite_course = @favorite_course_ids.include?(current_enrollment.course_id) %>
      <% past_course = enrollments_for_index(:past).include? current_enrollment %>
      <% favorite_past_course = past_course && favorite_course %>
      <% tooltip_message = t('nonfavorited_tooltip', "Click to add to the courses menu.") if !favorite_course %>
      <% tooltip_message = t("This course cannot be added to the courses menu unless the course is active.") if (!show_link || past_course) %>
      <% tooltip_message = t('favorited_tooltip', "Click to remove from the courses menu.") if favorite_course || favorite_past_course %>
        <span
          class="<%= "course-list-favorite-course" if favorite_course %> <%= "course-list-not-favoritable disabled" if (!show_link || favorite_past_course) %> <%= "course-list-favoritable" if show_link %>"
          data-tooltip="bottom"
          title="<%= tooltip_message %>"
          role="button"
          tabindex="0"
          data-course-id="<%= current_enrollment.course_id %>"
          <% if (show_link && (favorite_past_course || !(past_course && !favorite_course))) %>
              <%= "data-favorite-url=#{api_v1_add_favorite_course_url(current_enrollment.course_id)}" %>
          <% end %>
        >
          <i class="<%= "course-list-favorite-icon #{favorite_course ? "icon-star" : "icon-star-light"}" %>"></i>
          <span id="course_list_screenreader_message_<%= current_enrollment.course_id %>" class="screenreader-only">
            <%= tooltip_message %>
          </span>
        </span>
      </td>
      <% end %>

      <% course_color = @current_user.custom_colors["course_#{current_enrollment.course_id}"] %>
      <td class="course-list-course-title-column
        <%= "course-list-no-left-border" if @show_star_column %>
        <%= "course-list-not-favoritable" unless @show_star_column %>">
        <% if course_color.present? %>
          <span aria-hidden="true" class="course-color-block" style="<%= "color: #{course_color};" %>" ></span>
        <% end %>
        <% if show_link %><a href="<%= course_path(current_enrollment.course_id) %>" title="<%= current_enrollment.course.name %>"><% end %>
        <span class="name">
          <%= current_enrollment.course.name %>
        </span>
        <% if show_link %></a>
        <% end %>
      </td>

      <td class="course-list-no-left-border course-list-nickname-column">
        <%= current_enrollment.course.nickname_for(@current_user, nil) %>
      </td>

      <td class="course-list-no-left-border course-list-term-column">
      <% if current_enrollment.course.enrollment_term.default_term? %>
        <span class="screenreader-only"><%= current_enrollment.course.enrollment_term.name %></span>
      <% else %>
        <%= current_enrollment.course.enrollment_term.name %>
      <% end %>
      </td>

      <td class="course-list-no-left-border course-list-enrolled-as-column">
        <%= current_enrollment.readable_role_name %>
      </td>

      <td class="course-list-no-left-border course-list-published-column ">
        <% if current_enrollment.course.created? || current_enrollment.course.claimed? %>
            <span
              class="<%= 'course-list-unpublished-course' if unpublished_course_redesign %>"
              data-tooltip
              title="<%= t('unpublished_course_tooltip', "This course has not been published. Students should contact the course instructor for access.") %>">
              <%= t('unpublished_course', "No") %>
            </span>
             <span class="screenreader-only"><%= t('unpublished_course_tooltip', "This course has not been published. Students should contact the course instructor for access.") %></span>
        <% else %>
            <span data-tooltip title="<%= t('published_course_tooltip', "This course has been published.") %>"><%= t('published_course', "Yes") %></span>
             <span class="screenreader-only"><%= t('published_course_tooltip', "This course has been published.") %></span>
        <% end %>
      </td>

<% end %>
<% unless dashboard %>
  </tr>
<% end %>
