<% title t('conversations.title_html', count: @conversation.users.count - 1, users: (@conversation.users - [current_user]).map(&:name).to_sentence) %>

<div class="discussion-header">
  <h2>
    <%= t('conversations.title_html', count: @conversation.users.count - 1, users: (@conversation.users - [current_user]).map{ |u| link_to(u.name, user_path(u)) }.to_sentence.html_safe) %>
  </h2>
  <div class="discussion-actions">
    <div class="discussion-subscription-links <%= current_user.subscribed_to_conversation?(@conversation) ? 'discussion-subscribed' : 'discussion-not-subscribed' %>">
      <%= link_to t('discussions.subscribe'), subscribe_user_conversation_path(current_user, @conversation), data: { turbo: true, turbo_method: :POST }, class: 'discussion-subscribe' %>
      <%= link_to t('discussions.unsubscribe'), unsubscribe_user_conversation_path(current_user, @conversation), data: { turbo: true, turbo_method: :POST }, class: 'discussion-unsubscribe' %>
    </div>
  </div>
</div>

<%= render_pagination %>

<% @messages.each do |message| %>
  <% by_current_user = message.poster && current_user == message.poster %>
  <div class="comment" id="message-<%= message.id %>">
    <div class="comment-meta">
      <div class="comment-meta-item comment-meta-item-main">
        <%= render_poster(message) %>
      </div>
      <div class="comment-meta-item">
        <%= link_to('§', message.path(current_user, locale: I18n.locale), { class: 'self-link' }) %>
      </div>
      <div class="comment-meta-item">
        <%= t('discussions.comment_date', date: markup_date(message.created_at)).html_safe %>
      </div>
      <div class="comment-meta-spacer"></div>
      <% if message.editable_by?(current_user) %>
        <div class="comment-meta-item">
          <%= link_to t('discussions.edit_comment_link'), '#', class: 'edit-comment', data: { comment_container: "message-#{message.id}" } %>
        </div>
      <% end %>
      <div class="comment-meta-item">
        <%= link_to t('discussions.quote_comment'), '#', class: 'quote-comment' %>
      </div>
      <% unless by_current_user %>
        <div class="comment-meta-item">
          <%= link_to t('reports.report_message'), new_report_path(item_class: 'message', item_id: message.id), class: 'report-link' %>
        </div>
      <% end %>
    </div>
    <div class="user-content">
      <%= format_user_text(message.content, message.content_markup, mentions: message.mentions) %>
      <%= render partial: 'screenshots/show', locals: { attachable: message } %>
    </div>
    <% if message.editable_by?(current_user) %>
      <div class="edit-comment-form">
        <%= form_with(model: message, url: user_conversation_message_path(message.poster, message.conversation, message), method: :PATCH) do |f| %>
          <h3><%= t('conversations.edit_message_header') %></h3>
          <%= render partial: 'conversations/message_entry', locals: { f: f } %>
          <%= f.submit t('conversations.update_message_submit') %>
          <%= f.submit t('discussions.cancel_update_comment'), class: 'cancel-edit-comment', data: { comment_container: "message-#{message.id}" } %>
        <% end %>
      </div>
    <% end %>
  </div>
<% end %>

<%= render_pagination %>

<div id="post-reply" class="post-reply">
  <h3><%= t('discussions.new_comment_heading') %></h3>
  <% if @show_moderator_notice %>
    <p class="notice">
      <%= t('conversations.moderator_notice', site_name:) %>
    </p>
  <% end %>
  <%= render partial: 'shared/errors', locals: { resource: @message } %>
  <% if @conversation.users.include?(current_user) %>
    <%= form_with(model: @message, url: user_conversation_messages_path(current_user, @conversation), method: :POST) do |f| %>
      <%= render partial: 'conversations/message_entry', locals: { f: f } %>
      <%= f.submit t('discussions.new_comment_submit') %>
    <% end %>
  <% end %>
</div>
