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

<% admin_breadcrumb(link_to plural_resource_name(Spree::CustomerReturn), spree.admin_order_customer_returns_url(@order)) %>
<% admin_breadcrumb(@customer_return.number) %>

<% content_for :page_actions do %>
<% end %>

<% if @manual_intervention_return_items.any? %>
  <fieldset data-hook="manual_intervention_return_items" class="no-border-bottom">
    <legend align="center"><%= t('spree.manual_intervention_required') %></legend>
    <%= render partial: 'return_item_decision', locals: {return_items: @manual_intervention_return_items, show_decision: true} %>
  </fieldset>
<% end %>

<% if @pending_return_items.any? %>
  <fieldset data-hook="pending_return_items" class="no-border-bottom">
    <legend align="center"><%= t('spree.pending') %></legend>
    <%= render partial: 'return_item_decision', locals: {return_items: @pending_return_items, show_decision: true} %>
  </fieldset>
<% end %>

<% if @accepted_return_items.any? %>
  <fieldset data-hook="accepted_return_items" class="no-border-bottom">
    <legend align="center"><%= t('spree.accepted') %></legend>
    <%= render partial: 'return_item_decision', locals: {return_items: @accepted_return_items, show_decision: false} %>
  </fieldset>
<% end %>

<% if @rejected_return_items.any? %>
  <fieldset data-hook="rejected_return_items" class="no-border-bottom">
    <legend align="center"><%= t('spree.rejected') %></legend>
    <%= render partial: 'return_item_decision', locals: {return_items: @rejected_return_items, show_decision: false} %>
  </fieldset>
<% end %>

<% if !@customer_return.fully_reimbursed? && @pending_reimbursements.empty? %>
  <fieldset data-hook="reimbursements" class="no-border-bottom no-border-top align-center">
    <% if @customer_return.completely_decided? %>
      <%= form_for [:admin, @order, Spree::Reimbursement.new] do |f| %>
        <%= hidden_field_tag :build_from_customer_return_id, @customer_return.id %>
        <%= f.submit t('spree.create_reimbursement'), class: 'btn btn-primary' %>
      <% end %>
    <% else %>
      <div class="no-objects-found">
        <%= t('spree.unable_to_create_reimbursements') %>
      </div>
    <% end %>
  </fieldset>
<% end %>

<fieldset data-hook="reimbursements" class="no-border-bottom">
  <legend align="center"><%= plural_resource_name(Spree::Reimbursement) %></legend>
  <% if @customer_return.reimbursements.any? %>
    <%= render partial: 'reimbursements_table', locals: {reimbursements: @customer_return.reimbursements} %>
  <% else %>
    <div class="no-objects-found">
      <%= t('spree.none') %>
    </div>
  <% end %>
</fieldset>
