<%page args="course, enrollment, show_courseware_link, cert_status, show_email_settings, course_mode_info, show_refund_option" />

<%! from django.utils.translation import ugettext as _ %>
<%!
  from django.core.urlresolvers import reverse
  from courseware.courses import course_image_url, get_course_about_section
  import waffle
%>

<%
  cert_name_short = course.cert_name_short
  if cert_name_short == "":
    cert_name_short = settings.CERT_NAME_SHORT
  
  cert_name_long = course.cert_name_long
  if cert_name_long == "":
    cert_name_long = settings.CERT_NAME_LONG
%>

<%namespace name='static' file='../static_content.html'/>

<li class="course-item">
  <article class="course ${enrollment.mode}">
    <%
      course_target = reverse('info', args=[course.id])
    %>

    % if show_courseware_link:
      <a href="${course_target}" class="cover">
        <img src="${course_image_url(course)}" alt="${_('{course_number} {course_name} Cover Image').format(course_number=course.number, course_name=course.display_name_with_default) |h}" />
      </a>
    % else:
      <div class="cover">
        <img src="${course_image_url(course)}" alt="${_('{course_number} {course_name} Cover Image').format(course_number=course.number, course_name=course.display_name_with_default) | h}" />
      </div>
    % endif

    % if enrollment.mode == "verified":
      <span class="sts-enrollment">
        <span class="label">${_("Enrolled as: ")}</span>
        <img class="deco-graphic" src="${static.url('images/vcert-ribbon-s.png')}" alt="ID Verified Ribbon/Badge" />
        <span class="sts-enrollment-value">${_("ID Verified")}</span>
      </span>
    % endif

    <section class="info">
      <hgroup>
        <p class="date-block">
        % if course.has_ended():
        ${_("Course Completed - {end_date}").format(end_date=course.end_date_text)}
        % elif course.has_started():
        ${_("Course Started - {start_date}").format(start_date=course.start_date_text)}
        % elif course.start_date_is_still_default: # Course start date TBD
        ${_("Course has not yet started")}
        % else:   # hasn't started yet
        ${_("Course Starts - {start_date}").format(start_date=course.start_date_text)}
        % endif
        </p>
        <h2 class="university">${get_course_about_section(course, 'university')}</h2>
        <h3>
          % if show_courseware_link:
            <a href="${course_target}">${course.display_number_with_default | h} ${course.display_name_with_default}</a>
          % else:
            <span>${course.display_number_with_default | h} ${course.display_name_with_default}</span>
          % endif
        </h3>
      </hgroup>

      % if course.has_ended() and cert_status and not enrollment.mode == 'audit':
      <%include file='_dashboard_certificate_information.html' args='cert_status=cert_status,course=course, enrollment=enrollment'/>
      % endif

      % if course_mode_info['show_upsell']:
        <div class="message message-upsell has-actions is-expandable is-shown">

            <div class="wrapper-tip">
              <h4 class="message-title">
                <i class="icon-caret-down ui-toggle-expansion"></i>
                % if waffle.flag_is_active(request, 'alternate_upsell_copy'):
                  <span class="value">${_("Document your accomplishment!")}</span>
                % else:
                  <span class="value">${_("Challenge Yourself!")}</span>
                % endif
              </h4>
              <p class="message-copy">${_("Take this course as an ID-verified student.")}</p>
            </div>

            <div class="wrapper-extended">
                <p class="message-copy">${_("You can still sign up for an ID verified {cert_name_long} for this course. If you plan to complete the whole course, it is a great way to recognize your achievement. {link_start}Learn more about the verified {cert_name_long}{link_end}.").format(link_start='<a href="{}">'.format(marketing_link('WHAT_IS_VERIFIED_CERT')), link_end="</a>", cert_name_long=cert_name_long)}</p>

              <ul class="actions message-actions">
                <li class="action-item">
                  <a class="action action-upgrade" href="${reverse('course_modes_choose', kwargs={'course_id': course.id})}?upgrade=True">
                    <img class="deco-graphic" src="${static.url('images/vcert-ribbon-s.png')}" alt="ID Verified Ribbon/Badge">
                    <span class="wrapper-copy">
                      <span class="copy" id="upgrade-to-verified" data-course-id="${course.id}" data-user="${user.username}">${_("Upgrade to Verified Track")}</span>
                    </span>
                  </a>
                </li>
              </ul>
            </div>
        </div>
      %endif

      % if show_courseware_link:
        % if course.has_ended():
          <a href="${course_target}" class="enter-course archived">${_('View Archived Course')}</a>
        % else:
          <a href="${course_target}" class="enter-course">${_('View Course')}</a>
        % endif
      % endif

      % if enrollment.mode != "verified":
        ## Translators: The course's name will be added to the end of this sentence.
        <a href="#unenroll-modal" class="unenroll" rel="leanModal" data-course-id="${course.id}" data-course-number="${course.number}" onclick="document.getElementById('track-info').innerHTML='${_("Are you sure you want to unregister from")}'; document.getElementById('refund-info').innerHTML=''">
          ${_('Unregister')}
        </a>
      % elif show_refund_option:
        ## Translators: The course's name will be added to the end of this sentence.
        <a href="#unenroll-modal" class="unenroll" rel="leanModal" data-course-id="${course.id}" data-course-number="${course.number}" onclick="document.getElementById('track-info').innerHTML='${_("Are you sure you want to unregister from the verified {cert_name_long} track of").format(cert_name_long=cert_name_long)}';
        document.getElementById('refund-info').innerHTML=gettext('You will be refunded the amount you paid.')">
          ${_('Unregister')}
        </a>
      % else:
        ## Translators: The course's name will be added to the end of this sentence.
        <a href="#unenroll-modal" class="unenroll" rel="leanModal" data-course-id="${course.id}" data-course-number="${course.number}" onclick="document.getElementById('track-info').innerHTML='${_("Are you sure you want to unregister from the verified {cert_name_long} track of").format(cert_name_long=cert_name_long)}';
        document.getElementById('refund-info').innerHTML=gettext('The refund deadline for this course has passed, so you will not receive a refund.')">
          ${_('Unregister')}
        </a>
      % endif

% if show_email_settings:
        <a href="#email-settings-modal" class="email-settings" rel="leanModal" data-course-id="${course.id}" data-course-number="${course.number}" data-optout="${course.id in course_optouts}">${_('Email Settings')}</a>
% endif



  </section>
</article>
</li>
