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

{% block breadcrumbs %}{% endblock breadcrumbs %}

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

{% block meta_opengraph_contextuals %}
    <meta property="og:title" content="{{ current_page.get_title|truncatechars:65 }}">
    <meta property="og:url" content="{{ SITE.web_url }}{{ current_page.get_absolute_url }}">
{% endblock meta_opengraph_contextuals %}

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

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

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

      {% block snapshot %}
        {% 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 %}
      {% endblock snapshot %}

      {% block title %}
        <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>
      {% endblock title %}

      {% block introduction %}
        {% 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 %}
      {% endblock introduction %}

      {% block categories %}
        {% 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 variant="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 %}
      {% endblock categories %}

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

    <div class="course-detail__aside">

      {% block cover %}
        {% 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 %}
      {% endblock cover %}

      {% block main_organization %}
        {% 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 %}
      {% endblock main_organization %}

      {% block social_networks %}
        <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>
      {% endblock social_networks %}

      {% block synopsis %}
        {% 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>
                <svg role="img" class="icon course-detail__aside__synopsis__icon" aria-hidden="true">
                  <use xlink:href="{% static 'richie/icons.svg' %}#icon-clock" />
                </svg>
                {% trans "Duration:" %}
              </dt>
              <dd>{{ instance.get_duration_display|default:"NA" }}</dd>
              {% endif %}
              {% if instance.effort or current_page.publisher_is_draft %}
              <dt>
                <svg role="img" class="icon course-detail__aside__synopsis__icon" aria-hidden="true">
                  <use xlink:href="{% static 'richie/icons.svg' %}#icon-stopwatch" />
                </svg>
                {% trans "Effort:" %}
              </dt>
              <dd>{{ instance.get_effort_display|default:"NA" }}</dd>
              {% endif %}
            {% endrender_model_block %}
          </dl>
        </div>
        {% endif %}
      {% endblock synopsis %}

      {% block runs %}
        {% with runs_dict=course.get_course_runs_dict %}
          <div class="course-detail__aside__runs">
            {% block runs_open %}
              <div class="course-detail__aside__runs__block">
                <h2 class="course-detail__aside__runs__block__title">{% trans 'Course runs' %}</h2>
                {% for run in runs_dict.0|add:runs_dict.1 %}
                  {% include "courses/cms/fragment_course_run.html" %}
                {% empty %}
                  <div class="course-detail__aside__runs__block__empty">{% trans "No open course runs" %}</div>
                {% endfor %}
              </div>
            {% endblock runs_open %}

            {% block runs_to_be_scheduled %}
            {% if runs_dict.6 and current_page.publisher_is_draft %}
              <div class="course-detail__aside__runs__block">
                <h3 class="course-detail__aside__runs__block__title">
                  {% trans "To be scheduled" context "Course runs to be scheduled (plural)" %}
                </h3>
                {% include "courses/cms/fragment_course_runs_list.html" with course_runs=runs_dict.6 %}
              </div>
            {% endif %}
            {% endblock runs_to_be_scheduled %}

            {% block runs_upcoming %}
            {% if runs_dict.2 %}
              <div class="course-detail__aside__runs__block">
                <h3 class="course-detail__aside__runs__block__title">
                  {% trans "Upcoming" context "Upcoming course runs (plural)" %}
                </h3>
                {% include "courses/cms/fragment_course_runs_list.html" with course_runs=runs_dict.2 %}
              </div>
            {% endif %}
            {% endblock runs_upcoming %}

            {% block runs_ongoing %}
            {% if runs_dict.3 or runs_dict.4 %}
              <div class="course-detail__aside__runs__block">
                <h3 class="course-detail__aside__runs__block__title">
                  {% trans "Ongoing" context "Ongoing course runs (plural)" %}
                </h3>
                {% include "courses/cms/fragment_course_runs_list.html" with course_runs=runs_dict.3|add:runs_dict.4 %}
              </div>
            {% endif %}
            {% endblock runs_ongoing %}

            {% block runs_archived %}
            {% if runs_dict.5 %}
              <div class="course-detail__aside__runs__block">
                <h3 class="course-detail__aside__runs__block__title">
                  {% trans "Archived" context "Archived course runs (plural)" %}
                </h3>
                {% include "courses/cms/fragment_course_runs_list.html" with course_runs=runs_dict.5 %}
              </div>
            {% endif %}
            {% endblock runs_archived %}

          </div>
        {% endwith %}
      {% endblock runs %}
    </div>
    {% endwith %}

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