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

{% 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 "title" %}
        {% endif %}
      </h1>

      {% if current_page.publisher_is_draft or not current_page|is_empty_placeholder:"course_introduction" %}
      <div class="course-detail__content__row course-detail__content__introduction">
        {% page_placeholder "course_introduction" current_page %}
      </div>
      {% endif %}

      {% if current_page.publisher_is_draft or not current_page|is_empty_placeholder:"course_icons" or not current_page|is_empty_placeholder:"course_categories" %}
      <div class="course-detail__content__row course-detail__content__categories">
        {% with form_factor="tag" %}
          {% placeholder "course_icons" %}
          {% page_placeholder "course_categories" current_page or %}
            {% if current_page.publisher_is_draft and current_page|is_empty_placeholder:"course_icons" %}
              <p class="course-detail__content__categories__placeholder">
                {% trans "No associated categories" %}
              </p>
            {% endif %}
          {% endpage_placeholder %}
        {% endwith %}
      </div>
      {% endif %}

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

    <div class="course-detail__aside">

      {% if current_page.publisher_is_draft %}
      <div class="course-detail__aside__cover">
        {% get_placeholder_plugins "course_cover" as plugins or %}
          <p class="course-detail__aside__cover__empty">{% trans 'Add an image for course cover on its glimpse.' %}</p>
        {% endget_placeholder_plugins %}
        {% blockplugin plugins.0 %}
          <img
            src="{% thumbnail instance.picture 300x170 crop upscale subject_location=instance.picture.subject_location %}"
            srcset="
              {% thumbnail instance.picture 300x170 crop upscale subject_location=instance.picture.subject_location %} 300w,
              {% if instance.picture.width >= 600 %}{% thumbnail instance.picture 600x340 crop upscale subject_location=instance.picture.subject_location %} 600w,{% endif %}
              {% if instance.picture.width >= 900 %}{% thumbnail instance.picture 900x510 crop upscale subject_location=instance.picture.subject_location %} 900w{% endif %}
            "
            sizes="300px"
            alt="{% if instance.picture.default_alt_text %}{{ instance.picture.default_alt_text }}{% else %}{% trans 'course cover image' %}{% endif %}"
          />
        {% endblockplugin %}
      </div>
      {% endif %}

      {% with main_organization=course.get_main_organization %}
        {% if main_organization %}
          {% if current_page.publisher_is_draft %}
              {% if main_organization.check_publication is True %}
                  {% include "courses/cms/fragment_organization_main_logo.html" with organization=main_organization.public_extension %}
              {% else %}
                  {% include "courses/cms/fragment_organization_main_logo.html" with organization=main_organization %}
              {% endif %}
          {# If the current page is the published version, show only the organizations that are published #}
          {% elif main_organization.check_publication is True %}
              {% include "courses/cms/fragment_organization_main_logo.html" with organization=main_organization.public_extension %}
          {% endif %}
        {% else %}
          {% include "courses/cms/fragment_organization_main_logo.html" with organization=None %}
        {% endif %}
      {% endwith %}

      <div class="course-detail__aside__social-networks">
        {% include "social-networks/course-badges.html" with page_title=request.current_page.get_title page_url=request.current_page.get_absolute_url %}
      </div>

      {% if course.duration or course.effort or current_page.publisher_is_draft %}
      <div class="course-detail__aside__synopsis">
        <dl>
          {% render_model_block course "duration,effort" %}
            {% if instance.duration or current_page.publisher_is_draft %}
            <dt><span class="icon-duration"></span>{% trans "Duration:" %}</dt>
            <dd>{{ instance.get_duration_display|default:"NA" }}</dd>
            {% endif %}
            {% if instance.effort or current_page.publisher_is_draft %}
            <dt><span class="icon-effort"></span>{% trans "Effort:" %}</dt>
            <dd>{{ instance.get_effort_display|default:"NA" }}</dd>
            {% endif %}
          {% endrender_model_block %}
        </dl>
      </div>
      {% endif %}

      <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:'DATE_FORMAT'|default:'...'" as start %}
              {% render_model run "enrollment_end" "enrollment_start,enrollment_end" "" "date:'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:'DATE_FORMAT'|default:'...'" as start %}
              {% render_model run "end" "start,end" "" "date:'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.call_to_action %}
          <a class="course-detail__aside__run__block__cta" href="{{ run.extended_object.get_absolute_url }}">
            {{ run.state.call_to_action|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 %}
          <div class="course-detail__aside__run__empty">{% trans "No associated course runs" %}</div>
        {% endfor %}
      </div>
    </div>

    {% endwith %}

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