<article class="forum-post message" id="forum_post_<%= forum_post.id %>"
          data-forum-post-id="<%= forum_post.id %>"
          data-is-reported="<%= has_moderation_reports? %>"
          data-creator="<%= forum_post.creator.name %>">

  <div class="author">
    <div class="author-name">
      <%= link_to_user forum_post.creator %>
      <% if forum_post.is_deleted? %>
        (deleted)
      <% end %>
    </div>
    <%= link_to time_ago_in_words_tagged(forum_post.created_at), forum_post, class: "message-timestamp" %>
  </div>

  <div class="content">
    <div class="prose">
      <%= format_text(forum_post.body, data: dtext_data) %>
    </div>
    <%= render "application/update_notice", record: forum_post %>

    <menu>
      <% if policy(forum_post).create? %>
        <li><%= link_to "Reply", new_forum_post_path(post_id: forum_post.id), method: :get, remote: true %></li>
      <% end %>

      <% if policy(forum_post).destroy? && !forum_post.is_original_post?(original_forum_post_id) %>
        <% if forum_post.is_deleted %>
          <li><%= link_to "Undelete", undelete_forum_post_path(forum_post.id), method: :post, remote: true %></li>
        <% else %>
          <li><%= link_to "Delete", forum_post_path(forum_post.id), "data-confirm": "Are you sure you want to delete this forum post?", method: :delete, remote: true %></li>
        <% end %>
      <% end %>

      <% if policy(forum_post).update? %>
        <% if forum_post.is_original_post?(original_forum_post_id) %>
          <li><%= link_to "Edit", edit_forum_topic_path(forum_post.topic), id: "edit_forum_topic_link_#{forum_post.topic.id}", class: "edit_forum_topic_link" %></li>
        <% else %>
          <li><%= link_to "Edit", edit_forum_post_path(forum_post.id), id: "edit_forum_post_link_#{forum_post.id}", class: "edit_forum_post_link" %></li>
        <% end %>
      <% end %>

      <% if policy(forum_post).reportable? %>
        <li><%= link_to "Report", new_moderation_report_path(moderation_report: { model_type: "ForumPost", model_id: forum_post.id }), remote: true, title: "Report this forum post to the moderators" %></li>
      <% end %>

      <% if has_moderation_reports? %>
        <li class="moderation-report-notice">Reported (<%= link_to pluralize(forum_post.moderation_reports.length, "report"), moderation_reports_path(search: { model_type: "ForumPost", model_id: forum_post.id }) %>)</li>
      <% end %>

      <% if forum_post.bulk_update_request.present? %>
        <menu class="votes" id="forum-post-votes-for-<%= forum_post.id %>">
          <%= render "forum_post_votes/list", votes: forum_post.votes, forum_post: forum_post %>
        </menu>
      <% end %>
    </menu>

    <% if policy(forum_post).update? %>
      <% if forum_post.is_original_post?(original_forum_post_id) %>
        <%= render "forum_topics/form", forum_topic: forum_post.topic %>
      <% else %>
        <%= render "forum_posts/partials/edit/form", forum_post: forum_post %>
      <% end %>
    <% end %>
  </div>
</article>
