{% load i18n %}
<section class="replies"
         hx-target="this"
         hx-swap="outerHTML"
         id="replies_{{ post.pk }}">
  {% with parent_post=post %}
    {% for post in replies %}
      <div class="post">
        <span class="action">
          {% if post.author_id == request.user.identity.pk %}
            {% include "action_delete_post.html" %}
          {% endif %}
          {% include "action_reply_post.html" %}
          {% include "action_like_post.html" %}
          {% include "action_boost_post.html" %}
          {% include "action_open_post.html" %}
        </span>
        <span>
          <a href="{{ post.author.url }}"
             class="nickname"
             title="@{{ post.author.handle }}">{{ post.author.name|default:post.author.username }}</a>
        </span>
        <span class="action inline">
          <span class="timestamp">
            {% if post.edited %}
              {{ post.edited | date }}
              <i class="fa-solid fa-pencil"></i>
            {% elif post.published %}
              {{ post.published | date }}
            {% else %}
              {{ post.created | date }}
            {% endif %}
          </span>
        </span>
        {% if post.summary %}
          <details>
            <summary>{{ post.summary }}</summary>
            {{ post.safe_content_local }}
          </details>
        {% else %}
          {{ post.safe_content_local }}
        {% endif %}
        {% for attachment in post.attachments.all %}
          <a href="{{ attachment.full_url.relative }}" class="download">
            <div>
              <i class="fa-solid fa-download"></i> {{ attachment.file_display_name }}
            </div>
          </a>
        {% endfor %}
        <div id="replies_{{ post.pk }}"></div>
      </div>
    {% empty %}
      <div class="empty">{% trans 'no replies so far.' %}</div>
    {% endfor %}
  {% endwith %}
  {% if post %}
    <form class="reply"
          role="group"
          hx-post="{% url 'journal:post_reply' post.pk %}"
          hx-trigger="submit once">
      <input name="content" type="text" placeholder="{% trans "add a reply" %}" />
      <details class="dropdown">
        <summary>
          <i class="fa-solid fa-users-gear"></i>
        </summary>
        <ul>
          <li>
            <label>
              <input type="radio"
                     name="visibility"
                     value="{{ request.user.preference.post_public_mode }}"
                     {% if post.visibility <= 1 or post.visibility == 4 %}checked{% endif %} />
              <i class="fa-solid fa-globe"></i>
            </label>
          </li>
          <li>
            <label>
              <input type="radio"
                     name="visibility"
                     value="2"
                     {% if post.visibility == 2 %}checked{% endif %} />
              <i class="fa-solid fa-lock"></i>
            </label>
          </li>
          <li>
            <label>
              <input type="radio"
                     name="visibility"
                     value="3"
                     {% if post.visibility == 3 %}checked{% endif %} />
              <i class="fa-solid fa-at"></i>
            </label>
          </li>
        </ul>
      </details>
      <button class="secondary">
        <i class="fa-regular fa-paper-plane"></i>
      </button>
    </form>
  {% endif %}
</section>
