{% extends "richie/fullwidth.html" %}
{% load cms_tags i18n extra_tags %}

{% block meta %}
{# Make sure course snapshot pages are not indexed by search engines #}
{% if current_page.parent_page.course %}<meta name="robots" content="noindex">{% endif %}
{% endblock meta %}

{% block content %}{% spaceless %}
<div class="course-detail">
  {% spaceless %}

    {% with course=current_page.course header_level=2 %}

    <div class="course-detail__content course-detail__content--two">

      {% if request.current_page.parent_page.course %}
      <div class="course-detail__content__snapshot">
        <div class="course-detail__content__snapshot__date">
          {% blocktrans with creation_date=request.current_page.creation_date|date:"SHORT_DATE_FORMAT" %}
          Archived on {{ creation_date }}
          {% endblocktrans %}
        </div>
        <a href="{{ request.current_page.parent_page.get_absolute_url }}">{% trans "Go to current version" %}</a>
      </div>
      {% endif %}

      <h1 class="course-detail__content__title">
        {% if request.current_page.parent_page.course %}
          {{ request.current_page.parent_page.get_title }}
        {% else %}
          {% render_model request.current_page "titles" %}
        {% endif %}
      </h1>

      <div class="course-detail__content__row course-detail__content__categories">
          {% with form_factor="tag" %}
            {% page_placeholder "course_categories" current_page or %}
              <p class="course-detail__content__categories__placeholder">
                {% trans "No associated categories" %}
              </p>
            {% endpage_placeholder %}
          {% endwith %}
      </div>

      {% include "courses/cms/fragment_course_content.html" with page=current_page %}
    </div>

    <div class="course-detail__aside">

      <div class="course-detail__aside__cover">
        {% if current_page.publisher_is_draft %}
          {% placeholder "course_cover" or %}
          <p>{% trans 'Add an image for course cover on its glimpse.' %}</p>
          {% endplaceholder %}
        {% endif %}
      </div>

      <div class="course-detail__aside__main-org-logo">
        {% include "courses/cms/fragment_organization_main_logo.html" with organization=course.get_main_organization %}
      </div>

      <div class="course-detail__aside__run">
        <h2 class="course-detail__aside__run__title">{% trans 'Course runs' %}</h2>
        {% for run in course.get_course_runs_for_language %}
        <div class="course-detail__aside__run__block">
          <dl>
            <dt>{% trans "Enrollment" %}</dt>
            <dd>
              {% render_model run "enrollment_start" "enrollment_start,enrollment_end" "" "date:'SHORT_DATE_FORMAT'|default:'...'" as start %}
              {% render_model run "enrollment_end" "enrollment_start,enrollment_end" "" "date:'SHORT_DATE_FORMAT'|default:'...'" as end %}
              {% trans "From" %} {{ start|safe }} {% trans "to" %} {{ end|safe }}
            </dd>
            <dt>{% trans "Course" %}</dt>
            <dd>
              {% render_model run "start" "start,end" "" "date:'SHORT_DATE_FORMAT'|default:'...'" as start %}
              {% render_model run "end" "start,end" "" "date:'SHORT_DATE_FORMAT'|default:'...'" as end %}
              {% trans "From" %} {{ start|safe }} {% trans "to" %} {{ end|safe }}
            </dd>
            <dt>{% trans "Languages" %}</dt><dd>{% render_model run "get_languages_display" "languages" %}</dd>
            {% if current_page.publisher_is_draft %}
            <dt>{% trans "Resource link" %}</dt>
            <dd>
              <a href="{{ run.resource_link }}">
                {% render_model run "resource_link" "resource_link" %}
              </a>
            </dd>
            {% endif %}
          </dl>
          {% if run.state.cta %}
          <a class="course-detail__aside__run__block__cta" href="{{ run.extended_object.get_absolute_url }}">
            {{ run.state.cta|capfirst }}
          </a>
          {% else %}
          <a class="course-detail__aside__run__block__cta course-detail__aside__run__block__cta--projected" href="{{ run.extended_object.get_absolute_url }}">
            {{ run.state.text|capfirst }}
          </a>
          {% endif %}
        </div>
        {% empty %}
          {% trans "No associated course runs" %}
        {% endfor %}
      </div>
    </div>

    {% endwith %}

  {% endspaceless %}
</div>
{% endspaceless %}{% endblock content %}
