<div id="c-user-feedbacks">
  <div id="a-index">
    <h1>User Feedback</h1>

    <%= search_form_for(user_feedbacks_path) do |f| %>
      <%= f.input :user_name, input_html: { value: params.dig(:search, :user_name), "data-autocomplete": "user" } %>
      <%= f.input :creator_name, input_html: { value: params.dig(:search, :creator_name), "data-autocomplete": "user" } %>
      <%= f.input :body_matches, label: "Message", input_html: { value: params.dig(:search, :body_matches) } %>
      <%= f.input :category, collection: %w[positive neutral negative], include_blank: true, selected: params.dig(:search, :category) %>
      <% if policy(UserFeedback).can_view_deleted? %>
        <%= f.input :is_deleted, label: "Deleted", collection: %w[Yes No], include_blank: true, selected: params.dig(:search, :is_deleted) %>
      <% end %>
      <%= f.submit "Search" %>
    <% end %>

    <%= table_for @user_feedbacks, class: "striped autofit" do |t| %>
      <% t.column "User" do |feedback| %>
        <%= link_to_user feedback.user %>
        <%= link_to "»", user_feedbacks_path(search: { user_name: feedback.user.name }) %>
      <% end %>
      <% t.column "Message", td: {class: "col-expand"} do |feedback| %>
        <div class="prose">
          <%= format_text(feedback.body) %>
        </div>
        <%= render "application/update_notice", record: feedback, interval: 0.minutes %>
      <% end %>
      <% if policy(UserFeedback).can_view_deleted? %>
        <% t.column "Status" do |feedback| %>
          <%= "Deleted" if feedback.is_deleted? %>
        <% end %>
      <% end %>
      <% t.column "Category" do |feedback| %>
        <%= link_to feedback.category.capitalize, user_feedbacks_path(search: { category: feedback.category }) %>
      <% end %>
      <% t.column "Creator" do |feedback| %>
        <%= link_to_user feedback.creator %>
        <%= link_to "»", user_feedbacks_path(search: { creator_name: feedback.creator.name }) %>
        <div><%= time_ago_in_words_tagged(feedback.created_at) %></div>
      <% end %>
      <% t.column column: "control" do |feedback| %>
        <% if policy(feedback).update? %>
          <%= link_to "Edit", edit_user_feedback_path(feedback) %>
          <% if feedback.is_deleted? %>
            | <%= link_to "Undelete", user_feedback_path(feedback), method: :put, remote: true, "data-params": "user_feedback[is_deleted]=false" %>
          <% else %>
            | <%= link_to "Delete", user_feedback_path(feedback), method: :put, remote: true, "data-params": "user_feedback[is_deleted]=true", "data-confirm": "Are you sure you want to delete this user feedback?" %>
          <% end %>
        <% end %>
      <% end %>
    <% end %>

    <%= numbered_paginator(@user_feedbacks) %>
  </div>
</div>

<%= render "secondary_links" %>
