<h1>Post History</h1>

<div class="item-list">
  <% if [Question.post_type_id, Answer.post_type_id].include? @post.post_type_id %>
    <%= render 'posts/list', post: @post %>
  <% end %>
</div>

<% @history.each do |event| %>
  <details class="history-event">
    <summary>
      <strong><%= event.post_history_type.name.humanize %></strong>
      <span class="text-muted">
        by
        <% if event.user.nil? %>
          <span class="text-muted">(deleted user)</span>
        <% else %>
          <img alt="user avatar" src="<%= avatar_url(event.user) %>" height="16" width="16" />
          <%= link_to event.user&.username, user_path(event.user) %>
        <% end %>
        &middot;
        <%= event.created_at.iso8601 %> (<%= time_ago_in_words(event.created_at) %> ago)
        <% if event.comment.present? %>
          <br/>
          <span class="text-muted"><em><%= event.comment %></em></span>
        <% end %>
      </span>
    </summary>
    <% if event.before_title.present? || event.after_title.present? %>
      <%= render 'diff', before: event.before_title, after: event.after_title, post: @post %>
    <% end %>
    <%= render 'diff', before: event.before_state, after: event.after_state, post: @post %>
    <% if event.before_tags.present? || event.after_tags.present? %>
      <%= render 'diff', before: event.before_tags, after: event.after_tags, post: @post %>
    <% end %>
  </details>
<% end %>