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

<style>
  #right-side-wrapper {
    height: 100%;
  }
</style>

<% provide :page_title, @assignment.title %>
<% provide :right_side, render(:partial => "assignment_sidebar") %>

<% if @show_locked_page %>

  <h1><%= @assignment.title %></h1>
  <%= @locked.is_a?(Hash) ? lock_explanation(@locked, 'assignment', @context) : t(:assignment_locked, "This assignment is currently locked.") %>

<% else %>

<% if @assignment.omit_from_final_grade %>
  <div class="alert alert-info omit-from-final-warning">
    <%= t("This assignment does not count toward the final grade.") %>
  </div>
<% end %>
<div id="assignment_show" class="assignment content_underline_links">
  <% if can_do(@context, @current_user, :read_as_admin) %>
    <div class='assignment-title'>
      <div class='title-content'>
        <h1 class="title">
          <%= @assignment.title %>
        </h1>
      </div>
      <div class='assignment-buttons'>
        <button
          id="assignment_publish_button"
          data-id='<%= @assignment.id %>'
          class='btn <%= "published" if @assignment.published? %> <%= "disabled" unless assignment_publishing_enabled?(@assignment, @current_user) %>'>
        </button>
        <% if @context.grants_right?(@current_user, :manage_assignments) %>
          <a href="<%= edit_polymorphic_path([@context, @assignment]) %>" class='btn edit_assignment_link<%= ' disabled' unless can_do(@assignment, @current_user, :update) %>'>
            <i class='icon-edit'></i> <%= t('links.edit', 'Edit') %>
            <% unless can_do(@assignment, @current_user, :update) %>
              <span class="screenreader-only">You do not have permissions to edit this moderated assignment</span>
            <% end %>
          </a>
        <% end %>
        <%= assignment_submission_button(@assignment, @current_user, @current_user_submission) %>
        <% if show_moderation_link %>
          <a
            href='<%= course_assignment_moderate_url(@context, @assignment) %>'
            id="moderated_grading_button"
            class='Button'
            style='<%= "display:none" unless @assignment.published? %>'
          >
            <%= t('Moderate') %>
          </a>
        <% end %>

        <% if @assignment_menu_tools.present? || @can_direct_share %>
          <button class="al-trigger btn" aria-haspopup="true" aria-owns="toolbar-1">
            <i class="icon-more" aria-hidden="true"></i>
            <span class="screenreader-only"><%= t('manage', 'Manage') %></span>
          </button>
          <ul id="toolbar-1" class="al-options" role="menu" tabindex="0" aria-hidden="true" aria-expanded="false">
            <% if @can_direct_share %>
              <li role="presentation">
                <a href="#" class="icon-user direct-share-send-to-menu-item"><%= t("Send To...") %></a>
              </li>
              <li role="presentation">
                <a href="#" class="icon-duplicate direct-share-copy-to-menu-item"><%= t("Copy To...") %></a>
              </li>
            <% end %>
            <%= external_tools_menu_items(@assignment_menu_tools, {link_class: "menu_tool_link", settings_key: :assignment_menu, in_list: true, url_params: {:assignments => [@assignment.id]}}) %>
          </ul>
        <% end %>
      </div>
    </div>
    <div id="direct-share-mount-point"></div>
  <% else %>
    <!--Student View-->
    <% if show_confetti %>
      <%= render partial: "confetti" %>
    <% end %>
    <div class='assignment-title'>
      <div class='title-content'>
        <h1 class="title">
          <%= @assignment.title %>
        </h1>
      </div>
      <div class='assignment-buttons'>
        <%= render "shared/mark_as_done" %>
        <%= assignment_submission_button(@assignment, @current_user, @current_user_submission) %>
      </div>
    </div>
    <%= render "student_assignment_overview" %>
  <% end %>

  <div class="clear"></div>

  <% if @locked %>
    <%= @locked.is_a?(Hash) ? lock_explanation(@locked, 'assignment', @context) : t('messages.locked', "This assignment is currently locked.") %>
  <% end %>

  <div class="clear"></div>

  <% description = !@assignment.description.blank? ? public_user_content(@assignment.description) : t('defaults.no_content', "No Content") %>
  <div class="description user_content <%= can_do(@context, @current_user, :read_as_admin) ? "teacher-version" : "student-version" %>"><%= description %></div>

  <% if can_do(@context, @current_user, :read_as_admin) %>
    <!--Teacher view-->

    <form class="form-horizontal bootstrap-form display-only" style="margin-top:18px;">
      <fieldset>
        <div class="control-group">
          <div class="control-label"><%= t(:points, 'Points') %></div>
          <div class="controls">
            <span class="value points_possible"><%= n(round_if_whole(@assignment.points_possible)) || t(:no_points, 'None') %></span>
          </div>
        </div>
        <div class="control-group">
          <div class="control-label"><%= t :submitting, 'Submitting' %></div>
          <div class="controls">
            <span class="value"><%= @assignment.readable_submission_types || t(:no_submission, 'Nothing') %></span>
          </div>
        </div>
        <% if @assignment.submission_types =~ /online_upload/ && !@assignment.allowed_extensions.blank? -%>
          <div class="control-group">
            <div class="control-label"><%= t :submission_types, 'File Types' %></div>
            <div class="controls">
              <span class="value"><%= @assignment.allowed_extensions.to_sentence %></span>
            </div>
          </div>
        <% end -%>
        <% if @assignment.allowed_attempts&.> 0 %>
          <div class="control-group">
            <div class="control-label"><%= t :allowed_attempts, 'Allowed Attempts' %></div>
            <div class="controls">
              <span class="value"><%= @assignment.allowed_attempts %></span>
            </div>
          </div>
        <% end -%>
        <% if turnitin_active? %>
          <div class="control-group">
            <div class="control-label"><%= t :turnitin, 'Turnitin' %></div>
            <div class="controls">
              <span class="value"><%= t :turnitin_enabled, 'Turnitin has been enabled for this assignment.' %></span>
            </div>
          </div>
        <% end %>
        <% if vericite_active? %>
          <div class="control-group">
            <div class="control-label"><%= t :vericite, 'VeriCite' %></div>
            <div class="controls">
              <span class="value"><%= t :vericite_enabled, 'VeriCite has been enabled for this assignment.' %></span>
            </div>
          </div>
        <% end %>
      </fieldset>
    </form>

    <table class="ic-Table assignment_dates">
      <thead>
        <tr>
          <th scope="col"><%= t(:due, 'Due') %></th>
          <th scope="col"><%= t(:for, 'For') %></th>
          <th scope="col"><%= t(:available_from, 'Available from') %></th>
          <th scope="col"><%= t(:until, 'Until') %></th>
        </tr>
      </thead>

      <%= render 'shared/override_list', :assignment => @assignment,
        :user => @current_user %>

    </table>

    <% if can_do(@assignment, @current_user, :update) %>
      <div class="content-box">
        <a
          href="<%= context_url(@context, :context_rubrics_url) %>"
          class="add_rubric_link Button icon-plus"
          style="<%= hidden if @assignment.rubric_association %>"
        >
          <span aria-hidden="true"><%= t 'links.add_rubric', "Rubric" %></span>
          <span class="screenreader-only"><%= t('Add Rubric') %></span>
        </a>
      </div>
    <% end %>

    <div class="course_id" style="display: none;"><%= @context.id if @context && @context.is_a?(Course) %></div>

  <% end %>

  <div style="display: none;">
    <span class="timestamp"><%= @assignment.due_at.to_i %></span>
    <span class="due_date_string"><%= @assignment.due_at.strftime("%m/%d/%Y") rescue "" %></span>
    <span class="due_time_string"><%= @assignment.due_at.strftime("%I:%M%p").downcase rescue "" %></span>
  </div>
</div>

<% end %>

<% if !@locked && can_do(@assignment, @current_user, :submit) %>
  <%= render :partial => "submit_assignment", locals: { eula_url: eula_url }%>
<% end %>

<%= render partial: "shared/rubrics_component" %>
