<%= render partial: 'spree/admin/shared/order_tabs', locals: { current: 'Return Authorizations' } %>

<% content_for :page_actions do %>
  <% if @order.shipments.any? &:shipped? %>
    <li>
      <% if can? :manage, Spree::ReturnAuthorization %>
        <%= link_to t('spree.new_return_authorization'), new_admin_order_return_authorization_url(@order), class: 'btn btn-primary' %>
      <% end %>
    </li>
  <% end %>
<% end %>

<% admin_breadcrumb(plural_resource_name(Spree::ReturnAuthorization)) %>

<% if @order.shipments.any?(&:shipped?) || @order.return_authorizations.any? %>
  <table class="index">
    <thead data-hook="rma_header">
      <tr>
        <th><%= Spree::ReturnAuthorization.human_attribute_name(:number) %></th>
        <th><%= Spree::ReturnAuthorization.human_attribute_name(:state) %></th>
        <th><%= Spree::ReturnAuthorization.human_attribute_name(:total_excluding_vat) %></th>
        <th><%= Spree::ReturnAuthorization.human_attribute_name(:created_at) %></th>
        <th class="actions"></th>
      </tr>
    </thead>
    <tbody>
      <% @return_authorizations.each do |return_authorization| %>
        <tr id="<%= spree_dom_id(return_authorization) %>" data-hook="rma_row">
          <td><%= return_authorization.number %></td>
          <td>
            <span class="pill pill-<%= return_authorization.state %>">
              <%= t(
                return_authorization.state,
                scope: 'spree.return_authorization_states'
              ) %>
            </span>
          </td>
          <td><%= return_authorization.display_total_excluding_vat.to_html %></td>
          <td><%= pretty_time(return_authorization.created_at) %></td>
          <td class="actions">
            <% if can? :update, return_authorization %>
              <%= link_to_edit return_authorization, no_text: true, class: 'edit' %>
            <% end %>
            <% if can?(:destroy, return_authorization) && !return_authorization.customer_returned_items? %>
              <%= link_to_delete return_authorization, no_text: true %>
            <% end %>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
<% else %>
  <div data-hook="rma_cannot_create" class="no-objects-found">
    <%= t('spree.cannot_create_returns') %>
  </div>
<% end %>
