<%= render 'spree/admin/shared/taxes_tabs' %>

<% admin_breadcrumb(t('spree.settings')) %>
<% admin_breadcrumb(t('spree.admin.tab.taxes')) %>
<% admin_breadcrumb(plural_resource_name(Spree::TaxRate)) %>

<% content_for :page_actions do %>
  <% if can?(:create, Spree::TaxRate) %>
    <li>
      <%= link_to t('spree.new_tax_rate'), new_object_url, class: 'btn btn-primary' %>
    </li>
  <% end %>
<% end %>

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

<% content_for :table_filter do %>
  <%= search_form_for [:admin, @search], url: spree.admin_tax_rates_path do |f| %>
    <div class="row">
      <div class="col-md-6">
        <div class="field">
          <%= f.label :zone_id_eq, Spree::Zone.model_name.human %>
          <%= f.collection_select :zone_id_eq, @available_zones, :id, :name, { include_blank: t("spree.all") }, class: 'select2 fullwidth' %>
        </div>
      </div>
      <div class="col-md-6">
        <div class="field">
          <%= f.label :tax_categories_id_eq, Spree::TaxCategory.model_name.human %>
          <%= f.collection_select :tax_categories_id_eq, @available_categories, :id, :name, { include_blank: t("spree.all") }, class: 'select2 fullwidth' %>
        </div>
      </div>
    </div>
    <div class="filter-actions">
      <%= button_tag t("spree.filter_results"), class: "btn btn-primary" %>
    </div>
  <% end %>
<% end %>

<% if @tax_rates.any? %>
  <%= paginate @tax_rates, scope: spree, theme: "solidus_admin" %>

  <table class="index">
    <colgroup>
      <col style="width: 15%">
      <col style="width: 15%">
      <col style="width: 10%">
      <col style="width: 10%">
      <col style="width: 5%">
      <col style="width: 5%">
      <col style="width: 10%">
      <col style="width: 15%">
      <col style="width: 15%">
    </colgroup>
    <thead>
      <tr data-hook="rate_header">
        <th><%= Spree::TaxRate.human_attribute_name(:zone) %></th>
        <th><%= Spree::TaxRate.human_attribute_name(:name) %></th>
        <th><%= Spree::TaxRate.human_attribute_name(:tax_categories) %></th>
        <th><%= Spree::TaxRate.human_attribute_name(:amount) %></th>
        <th><%= Spree::TaxRate.human_attribute_name(:included_in_price) %></th>
        <th><%= Spree::TaxRate.human_attribute_name(:show_rate_in_label) %></th>
        <th><%= Spree::TaxRate.human_attribute_name(:expires_at) %></th>
        <th><%= Spree::Calculator.model_name.human %></th>
        <th class="actions"></th>
      </tr>
    </thead>
    <tbody>
      <% @tax_rates.each do |tax_rate| %>
      <tr id="<%= spree_dom_id tax_rate %>" data-hook="rate_row">
        <td><%= tax_rate.zone.try(:name) || t('spree.not_available') %></td>
        <td><%= tax_rate.name %></td>
        <td>
          <% if tax_rate.tax_categories.any? %>
            <%= tax_rate.tax_categories.map(&:name).join(", ") %>
          <% else %>
            <%= t('spree.not_available') %>
          <% end %>
        </td>
        <td><%= tax_rate.amount %></td>
        <td><%= tax_rate.included_in_price? ? t('spree.say_yes') : t('spree.say_no') %></td>
        <td><%= tax_rate.show_rate_in_label? ? t('spree.say_yes') : t('spree.say_no') %></td>
        <td><%= tax_rate.expires_at.to_date.to_fs(:short_date) if tax_rate.expires_at %></td>
        <td><%= tax_rate.calculator && tax_rate.calculator.class.model_name.human %></td>
        <td class="actions">
          <% if can?(:update, tax_rate) %>
            <%= link_to_edit tax_rate, no_text: true %>
          <% end %>
          <% if can?(:destroy, tax_rate) %>
            <%= link_to_delete tax_rate, no_text: true %>
          <% end %>
        </td>
      </tr>
      <% end %>
    </tbody>
  </table>

  <%= paginate @tax_rates, scope: spree, theme: "solidus_admin" %>
<% else %>
  <div class="no-objects-found">
    <%= render 'spree/admin/shared/no_objects_found',
                 resource: Spree::TaxRate,
                 new_resource_url: new_object_url %>
  </div>
<% end %>
