<div class="notification-list-header">
  <h2><%= t('users.notifications.list.header') %></h2>
  <% if notification_widget_count %>
    <div class="notification-actions">
      <%= link_to t('users.notifications.list.mark_all_read'), mark_all_read_notifications_path(user: current_user), data: { turbo: true, turbo_method: :post } %>
    </div>
  <% end %>
</div>

<% if @notifications.any? %>
  <div class="notification-list">
    <% @notifications.select(&:item).each do |notification| %>
      <div class="notification-list-item notification-<%= notification.read? ? 'read' : 'not-read' %> notification-type-<%= notification.notification_type %>">
        <div class="notification-meta">
          <div class="notification-meta-item">
            <%= markup_date(notification.created_at) %>
          </div>
        </div>
        <%= link_to notification.path(locale: I18n.locale) do
              case notification.notification_type.to_sym
              when Notification::NOTIFICATION_TYPE_NEW_CONVERSATION
                other_user = notification.item.users.where.not(id: current_user.id).first
                t('users.notifications.new_conversation', user: render_user_text(other_user, other_user&.id), text: notification.item.messages.first.plain_text.truncate(200))
              when Notification::NOTIFICATION_TYPE_NEW_MESSAGE
                t('users.notifications.new_message', user: render_user_text(notification.item.poster, notification.item.poster_id), text: notification.item.plain_text.truncate(200))
              when Notification::NOTIFICATION_TYPE_REPORT_RESOLVED_REPORTER
                case notification.item.result
                when Report::RESULT_DISMISSED
                  t('users.notifications.report_resolved_reporter.dismissed', item: report_item_text(notification.item))
                when Report::RESULT_FIXED
                  t('users.notifications.report_resolved_reporter.fixed', item: report_item_text(notification.item))
                when Report::RESULT_UPHELD
                  t('users.notifications.report_resolved_reporter.upheld', item: report_item_text(notification.item))
                else
                  raise "Unexpected report result '#{notification.item.result}' for notification #{notification.id}."
                end
              when Notification::NOTIFICATION_TYPE_REPORT_REBUTTED_REPORTER
                t('users.notifications.report_resolved_reporter.rebutted', item: report_item_text(notification.item))
              when Notification::NOTIFICATION_TYPE_REPORT_FILED_REPORTED
                t('users.notifications.report_filed_reported', item: report_item_text(notification.item))
              when Notification::NOTIFICATION_TYPE_REPORT_RESOLVED_REPORTED
                case notification.item.result
                when Report::RESULT_DISMISSED
                  t('users.notifications.report_resolved_reported.dismissed', item: report_item_text(notification.item))
                when Report::RESULT_FIXED
                  t('users.notifications.report_resolved_reported.fixed', item: report_item_text(notification.item))
                when Report::RESULT_UPHELD
                  t('users.notifications.report_resolved_reported.upheld', item: report_item_text(notification.item))
                else
                  raise "Unexpected report result '#{notification.item.result}' for notification #{notification.id}."
                end
              when Notification::NOTIFICATION_TYPE_NEW_COMMENT
                if notification.item.first_comment? && notification.item.script
                  t('users.notifications.new_comment_script', user: render_user_text(notification.item.poster, notification.item.poster_id), script: notification.item.script.name(locale: request_locale))
                else
                  t('users.notifications.new_comment', user: render_user_text(notification.item.poster, notification.item.poster_id), discussion: notification.item.discussion.display_title(locale: I18n.locale))
                end
              when Notification::NOTIFICATION_TYPE_MENTION
                t('users.notifications.mention', user: render_user_text(notification.item.poster, notification.item.poster_id), discussion: notification.item.discussion.display_title(locale: I18n.locale))
              when Notification::NOTIFICATION_TYPE_CONSECUTIVE_BAD_RATINGS
                t('users.notifications.consecutive_bad_ratings', script: notification.item.name(locale: I18n.locale))
              else
                raise "Unexpected notification type '#{notification.notification_type}' for notification #{notification.id}."
              end
        end %>
      </div>
    <% end %>
  </div>

  <%= render_pagination %>
<% else %>
  <h2><%= t('users.notifications.list.none') %></h2>

<% end %>

<p><%= link_to t('users.notifications.list.edit_settings'), notification_settings_user_path(current_user) %></p>