{% extends "aircox/public.html" %}
{% load static i18n humanize honeypot aircox %}
{% comment %}
Base template used to display a Page

Context:
- page: page
- parent: parent page
- related_objects: list of object to display as related publications
- related_url: url to the full list of related_objects
{% endcomment %}

{% block breadcrumbs %}
{% if parent %}
    {% include "./widgets/breadcrumbs.html" with page=parent %}
    {% if page %}
    <a href="{% url page.list_url_name parent_slug=parent.slug %}">
        {{ page|verbose_name:True }}
    </a>
    {% endif %}
{% elif page %}
    {% include "./widgets/breadcrumbs.html" with page=page no_title=True %}
{% endif %}
{% endblock %}

{% block title-container %}
{{ block.super }}
{% block page-actions %}
    {% include "aircox/widgets/page_actions.html" %}
{% endblock %}
{% endblock %}

{% block main %}
{{ block.super }}

{% block related %}
{% if related_objects %}
<section class="container">
    {% with models=object|verbose_name:True %}
    <h2 class="title is-2">{% blocktranslate %}Related {{models}}{% endblocktranslate %}</h2>

    {% include "./widgets/carousel.html" with objects=related_objects url_name=object.list_url_name url_category=object.category %}
    {% endwith %}
</section>
{% endif %}
{% endblock %}

{% block comments %}
{% if comments %}
<section class="container">
    <h2 class="title is-2">{% translate "Comments" %}</h2>

    {% for object in comments %}
    {% page_widget "item" object %}
    {% endfor %}
</section>
{% endif %}

{% if comment_form %}
<section class="container">
    <h2 class="title is-2">{% translate "Post a comment" %}</h2>
    <form method="POST">
        {% csrf_token %}
        {% render_honeypot_field "website" %}

        <div class="field">
            <div class="control">
                {{ comment_form.content }}
            </div>
        </div>

        {% for field in comment_form %}
        {% if field.name != "content" %}
        <div class="field is-horizontal">
            <label class="label">{{ field.label }}</label>
            <div class="control">{{ field }}</div>
        </div>
        {% if field.errors %}
        <p class="help is-danger">{{ field.errors }}</p>
        {% endif %}
        {% if field.help_text %}
        <p class="help">{{ field.help_text|safe }}</p>
        {% endif %}
        {% endif %}
        {% endfor %}

        <div class="has-text-right">
            <button type="submit" class="button">{% translate "Post comment" %}</button>
        </div>
    </form>
</section>
{% endif %}

{% endblock %}
{% endblock %}
