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

{% block content %}{% spaceless %}
{% with category=current_page.category header_level=2 blogposts=current_page.category.get_blogposts courses=current_page.category.get_courses %}
<div class="category-detail">
  <div class="category-detail__banner">
    {% placeholder "banner" or %}
      <div class="category-detail__banner__empty">{% trans "Banner" %}</div>
    {% endplaceholder %}
  </div>

  <div class="category-detail__logo">
    {% with width=216 height=120 %}
      {% placeholder "logo" or %}
        <div class="category-detail__logo__empty">{% trans "Logo" %}</div>
      {% endplaceholder %}
    {% endwith %}
  </div>

  <h1 class="category-detail__title">{% render_model request.current_page "title" %}</h1>

  <div class="category-detail__content">
    <div class="category-detail__content__description">
      {% placeholder "description" %}
    </div>
  </div>
</div>

{% if blogposts %}
<div class="blogpost-glimpse-list">
  <h2 class="blogpost-glimpse-list__title">{% trans "Related news" %}</h2>
  {% for blogpost in blogposts %}
    {# If the current page is a draft, show draft courses with a class annotation for styling #}
    {% if current_page.publisher_is_draft %}
      {% if blogpost.check_publication is True %}
      <a class="blogpost-glimpse blogpost-glimpse--link" href="{{ blogpost.public_extension.extended_object.get_absolute_url }}">
        {% include "courses/cms/fragment_blogpost_glimpse.html" with blogpost=blogpost.public_extension.extended_object %}
      </a>
      {% else %}
      <a class="blogpost-glimpse blogpost-glimpse--link blogpost-glimpse--draft" href="{{ blogpost.extended_object.get_absolute_url }}">
        {% include "courses/cms/fragment_blogpost_glimpse.html" with blogpost=blogpost.extended_object %}
      </a>
      {% endif %}
    {# If the current blogpost page is the published version, show only the blogposts that are published #}
    {% elif blogpost.check_publication is True %}
      <a class="blogpost-glimpse blogpost-glimpse--link" href="{{ blogpost.extended_object.get_absolute_url }}">
        {% include "courses/cms/fragment_blogpost_glimpse.html" with blogpost=blogpost.public_extension.extended_object %}
      </a>
    {% endif %}
  {% empty %}
    <div class="blogpost-glimpse blogpost-glimpse--empty">
      {% trans "No associated blogposts" %}
    </div>
  {% endfor %}
</div>
{% endif %}

{% if courses %}
<div class="course-glimpse-list">
  <h2 class="course-glimpse-list__title">{% trans "Related courses" %}</h2>
  {% for course in courses %}
    {# If the current page is a draft, show draft courses with a class annotation for styling #}
    {% if current_page.publisher_is_draft %}
      {% if course.check_publication is True %}
      <a class="course-glimpse course-glimpse--link" href="{{ course.public_extension.extended_object.get_absolute_url }}">
        {% include "courses/cms/fragment_course_glimpse.html" with course=course.public_extension %}
      </a>
      {% else %}
      <a class="course-glimpse course-glimpse--link course-glimpse--draft" href="{{ course.extended_object.get_absolute_url }}">
        {% include "courses/cms/fragment_course_glimpse.html" with course=course %}
      </a>
      {% endif %}
    {# If the current course page is the published version, show only the courses that are published #}
    {% elif course.check_publication is True %}
      <a class="course-glimpse course-glimpse--link" href="{{ course.extended_object.get_absolute_url }}">
        {% include "courses/cms/fragment_course_glimpse.html" with course=course.public_extension %}
      </a>
    {% endif %}
  {% endfor %}
</div>
{% endif %}

{% endwith %}
{% endspaceless %}{% endblock content %}
