{% extends 'base.html' %}

{% load flatpages %}

{% block title %}Blackboard{% endblock %}

{% block content %}
	<!-- Main Content -->
	<main class="container mx-auto w-full px-4 mt-8 flex-1">
		<h1 class="page-title">Blackboard</h1>

		<div class="lg:w-2/3 xl:w-7/12 mx-auto">
            {% get_flatpages '/blackboard-info/' as bb_infos %}
            {% if bb_infos %}
                <section class="my-8 flex flex-col gap-2">
                    <div class="db-page-content">
                        <!-- Content from DB here: -->
                        {{ bb_infos.first.content|safe }}
                    </div>

                    {% if request.user.is_authenticated %}
                        <a href="{% url 'admin:core_customflatpage_change' bb_infos.first.id %}" class="self-center sm:self-end btn-small btn-primary w-full sm:w-auto max-w-sm">
                            <i class="fa-regular fa-pen-to-square mr-1"></i>Info-Text bearbeiten
                        </a>
                    {% endif %}
                </section>
            {% endif %}

            {% if job_postings %}
                <section class="my-8 flex flex-col gap-2">
                    <div class="jobsList">
                        {% for job in job_postings %}
                            {% if not forloop.first %}
                                <hr>
                            {% endif %}

                            {% include 'blackboard/partials/_show_job_posting.html' %}
                        {% endfor %}
                    </div>

                    {% if request.user.is_authenticated %}
                        <div class="inline-flex flex-col sm:flex-row sm:justify-end gap-2 w-full sm:w-auto">
                            <a href="{% url 'admin:blackboard_jobposting_add' %}" class="self-center block btn-small btn-primary w-full sm:w-auto max-w-sm">
                                <i class="fa-regular fa-square-plus mr-1"></i>Neuer Eintrag
                            </a>
                        </div>
                    {% endif %}
                </section>
            {% else %}
                <section class="my-8 p-8 flex flex-col gap-2 items-center border-2 border-dashed rounded border-gray-300 dark:border-gray-600">
                    {% get_flatpages '/blackboard-blank/' as bb_blanks %}
                    {% if bb_blanks %}
                        <div class="text-center text-gray-600 dark:text-gray-300">
					        <i class="fa-solid fa-sparkles text-gray-400 dark:text-gray-400 text-2xl mb-4"></i>
                            {{ bb_blanks.first.content|safe }}
                        </div>
                    {% endif %}

                    {% if request.user.is_authenticated %}
                        <div class="inline-flex flex-col sm:flex-row gap-2 w-full sm:w-auto">
                            <a href="{% url 'admin:blackboard_jobposting_add' %}" class="self-center block btn-small btn-primary w-full sm:w-auto max-w-sm">
                                <i class="fa-regular fa-square-plus mr-1"></i>Neuer Eintrag
                            </a>
                            {% if bb_blanks %}
                                <a href="{% url 'admin:core_customflatpage_change' bb_blanks.first.id %}" class="self-center block btn-small btn-primary w-full sm:w-auto max-w-sm">
                                    <i class="fa-solid fa-asterisk mr-1"></i>Fülltext bearbeiten
                                </a>
                            {% endif %}
                        </div>
                    {% endif %}
                </section>
            {% endif %}
		</div>
	</main>
{% endblock %}
