<div class="row">
  <div class="col-md-12">
    <div class="d-md-flex d-sm-flex flex-sm-column flex-md-row flex-md-wrap mb-3">
      <% if policy(MaterialRelease).new? %>
        <%= link_to fa_icon("plus", text: t(".actions.new")), [:new, @project, :material_release], class: "btn btn-primary mr-2 mb-2" %>
      <% end %>

      <% if @material_releases.any? && policy(MaterialRelease).tag_multiple? %>
        <%= button_to_bulk_tagging(@project) %>
      <% end %>

      <% if @material_releases.any? && policy(MaterialRelease).download_multiple? %>
        <%= link_to "Download All", [@project, :contract_downloads, release_type: @material_releases.name], method: :post, remote: true, class: "btn btn-light border ml-auto mr-2 mb-2", data: {
            disable_with: "Please wait..." } %>
      <% end %>

      <%= bootstrap_form_with url: [@project, :material_releases], method: :get, remote: true, layout: :inline, id: "search" do |form| %>
        <%= form.search_field :query, hide_label: true, placeholder: t(".actions.search"), class: "rounded-pill-right", value: params[:query], prepend: form.button(fa_icon("search"), class: "btn btn-light border mb-2 rounded-pill-left") %>
      <% end %>
    </div>
  </div>
</div>

<div class="border bg-white rounded shadow-sm pb-3 table-responsive">
  <table class="table table-striped tr-px-4 align-all-middle">
    <thead class="thead-light">
      <tr>
        <th data-behavior="all-selectable"><%= check_box_tag "material_release_ids[]", false, false %></th>
        <th></th>
        <th><%= MaterialRelease.human_attribute_name(:name) %></th>
        <th><%= t(".table_headers.notes") %></th>
        <th><%= t(".table_headers.tags") %></th>
         <th><%= t(".table_headers.signed_at") %></th>

        <th></th>
      </tr>
    </thead>
    <tbody id="material_releases">
      <% if @material_releases.any? %>
        <%= render @material_releases %>
      <% else %>
        <tr>
          <td colspan="12" class="py-4 text-center text-muted"><%= t(".empty") %></td>
        </tr>
      <% end %>
    </tbody>
  </table>
</div>

<div id="material_releases_pagination" class="mt-3">
  <%= will_paginate @material_releases %>
</div>
