<div id="c-user-upgrades">
  <div id="a-index">
    <%= search_form_for(user_upgrades_path) do |f| %>
      <%= f.input :recipient_name, label: "Recipient", input_html: { value: params[:search][:recipient_name], data: { autocomplete: "user" } } %>
      <%= f.input :purchaser_name, label: "Purchaser", input_html: { value: params[:search][:purchaser_name], data: { autocomplete: "user" } } %>
      <%= f.input :upgrade_type, collection: UserUpgrade.upgrade_types, include_blank: true, selected: params[:search][:upgrade_type] %>
      <%= f.input :status, collection: UserUpgrade.statuses, include_blank: true, selected: params[:search][:status] %>
      <%= f.input :is_gifted, label: "Gifted?", as: :select, include_blank: true, selected: params[:search][:is_gifted] %>
      <%= f.submit "Search" %>
    <% end %>

    <%= table_for @user_upgrades, class: "striped autofit" do |t| %>
      <% t.column "Recipient" do |user_upgrade| %>
        <%= link_to_user user_upgrade.recipient %>
      <% end %>

      <% t.column "Purchaser" do |user_upgrade| %>
        <%= link_to_user user_upgrade.purchaser %>
      <% end %>

      <% t.column :upgrade_type do |user_upgrade| %>
        <%= user_upgrade.upgrade_type.humanize %>
      <% end %>

      <% t.column "Gifted?" do |user_upgrade| %>
        <%= "Yes" if user_upgrade.is_gift? %>
      <% end %>

      <% t.column :status %>

      <% t.column "Updated" do |user_upgrade| %>
        <%= time_ago_in_words_tagged(user_upgrade.updated_at) %>
      <% end %>

      <% t.column column: "control" do |user_upgrade| %>
        <%= link_to "Show", user_upgrade %>
        <% if policy(user_upgrade).receipt? %>
          | <%= link_to "Receipt", receipt_user_upgrade_path(user_upgrade), target: "_blank" %>
        <% end %>
        <% if policy(user_upgrade).payment? %>
          | <%= link_to "Payment", payment_user_upgrade_path(user_upgrade), target: "_blank" %>
        <% end %>
        <% if policy(user_upgrade).refund? %>
          | <%= link_to "Refund", refund_user_upgrade_path(user_upgrade), remote: true, method: :put, "data-confirm": "Are you sure you want to refund this payment?" %>
        <% end %>
      <% end %>
    <% end %>

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