{% extends "cast/cast_base.html" %}
{% load i18n %}
{% load static %}

{% if comments_enabled %}
  {% load comments %}
{% endif %}

{% block css %}
  {{ block.super }}
  {% if comments_enabled %}
    <link rel="stylesheet" type="text/css" href="{% static 'fluent_comments/css/ajaxcomments.css' %}" />
  {% endif %}
{% endblock css %}

{% block content %}
<a class="btn btn-secondary btn-lg" href="{% url "cast:post_list" slug=post.blog.slug %}" role="button">Back to Blog</a>
{% if user.is_authenticated %}
  <a class="btn btn-primary btn-lg" role="button" href="{% url "cast:post_update" blog_slug=post.blog.slug slug=post.slug %}">Update Entry</a>
{% endif %}
<article>
  <header>
    <h1>{{ post.title }}</h1>
    <a href="{% url "cast:post_detail" blog_slug=post.blog.slug slug=post.slug %}">
        <time date-time="{{ post.visible_date|date:"c" }}">{{ post.visible_date|date}}</time>
    </a>
    <span class="author">{{ post.author.username | title}}</span>
  </header>
  <section>
    {{ post.description|safe }}
  </section>
</article>

{% if comments_enabled %}
  <p>
    <h4>{% trans "Comments" %}:</h4>
    {% render_comment_list for object %}
    {% render_comment_form for object %}
  </p>
{% endif %}

{% endblock content %}


{% block javascript %}
  {% if comments_enabled %}
     <!-- recent jquery is needed for fluent-comments -->
     <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>    
    <script type="text/javascript" src="{% static 'fluent_comments/js/ajaxcomments.js' %}"></script>
  {% endif %}
  <!-- block.super needs to be below full jquery because otherwise jquery-slim would overwrite calls necessary for comments -->
  {{ block.super }}
  <script src="{% static 'js/cast/gallery.js' %}"></script>
  {% if comments_enabled %}
    <script type="text/javascript" src="{% static 'fluent_comments/js/ajaxcomments.js' %}"></script>
  {% endif %}
  {% if post.has_audio %}
    <script src="https://cdn.podlove.org/web-player/embed.js"></script>
    {% for pk, audio in post.media_lookup.audio.items %}
      <script>podlovePlayer("#audio_{{pk}}", "{{audio.podlove_url}}");</script>
    {% endfor %}
  {% endif %}

{% endblock javascript %}
