<% admin_breadcrumb(t('spree.settings')) %>
<% admin_breadcrumb(t('spree.admin.tab.shipping')) %>
<% if can?(:show, Spree::StockLocation) %>
  <% admin_breadcrumb(link_to plural_resource_name(Spree::StockLocation), spree.admin_stock_locations_path) %>
<% else %>
  <% admin_breadcrumb(plural_resource_name(Spree::StockLocation)) %>
<% end %>
<% if can?(:update, @stock_location) %>
  <% admin_breadcrumb(link_to(admin_stock_location_display_name(@stock_location), spree.edit_admin_stock_location_path(@stock_location.id))) %>
<% else %>
  <% admin_breadcrumb(admin_stock_location_display_name(@stock_location)) %>
<% end %>
<% admin_breadcrumb(plural_resource_name(Spree::StockMovement)) %>

<% content_for :table_filter_title do %>
  <%= t('spree.filter') %>
<% end %>

<% content_for :table_filter do %>
  <%= search_form_for(
    [:admin, @search],
    url: admin_stock_location_stock_movements_path(params[:stock_location_id])
  ) do |f| %>
    <div class="row">
      <div class="field-block col-12 col-md-6 col-lg-4 col-xl-3">
        <div class="field">
          <%= label_tag :q_variant_sku_eq, "#{t('spree.variant')} #{t('spree.sku')}" %>
          <%= f.text_field :variant_sku_eq, value: params[:q][:variant_sku_eq] %>
        </div>
      </div>
    </div>

    <div class="clearfix"></div>

    <div class="actions filter-actions">
      <%= button_tag t('spree.filter_results'), class: 'btn btn-primary' %>
    </div>
  <% end %>
<% end %>

<% if @stock_movements.any? %>
<table class="index" id='listing_stock_movements'>
  <colgroup>
    <col style="width: 35%">
    <col style="width: 20%">
    <col style="width: 45%">
  </colgroup>
  <thead>
    <tr data-hook="admin_stock_movements_index_headers">
      <th><%= Spree::StockMovement.human_attribute_name(:variant) %></th>
      <th><%= Spree::StockMovement.human_attribute_name(:quantity) %></th>
      <th><%= Spree::StockMovement.human_attribute_name(:originated_by) %></th>
    </tr>
  </thead>
  <tbody>
    <% @stock_movements.each do |stock_movement| %>
      <tr id="<%= spree_dom_id stock_movement %>" data-hook="admin_stock_movements_index_rows">
        <td><%= display_variant(stock_movement) %></td>
        <td><%= stock_movement.quantity %></td>
        <td><%= pretty_originator(stock_movement) %></td>
      </tr>
    <% end %>
  </tbody>
</table>
<% else %>
  <div class="no-objects-found">
    <%= render 'spree/admin/shared/no_objects_found',
                 resource: Spree::StockMovement %>
  </div>
<% end %>

<%= paginate @stock_movements, theme: "solidus_admin" %>
