<% content_for :page_title do %>
  <%= Spree.t(:"admin.user.stores") %>
<% end %>

<% content_for :page_actions do %>
  <%= button_link_to Spree.t(:add_store), spree.new_admin_store_path(@user), class: "btn-success", icon: 'add.svg' if can?(:create, Spree::Store) %>
<% end %>

<% if @stores.any? %>
<div class="table-responsive border rounded bg-white">
  <table class="table">
    <thead class="text-muted">
      <th><%= Spree.t(:name) %></th>
      <th><%= Spree.t(:url) %></th>
      <th><%= Spree.t(:supported_currencies) %></th>
      <th><%= Spree.t(:supported_locales) %></th>
      <th><%= Spree.t(:default) %>?</th>
      <th data-hook="admin_stores_index_header_actions" class="actions"></th>
    <thead class="text-muted">
    <tbody>
      <% @stores.each do |store| %>
        <tr>
          <td><%= store.unique_name %></td>
          <td><%= link_to store.url, store.formatted_url, target: :blank %></td>
          <td><%= store.supported_currencies_list.map(&:iso_code).join(', ') %></td>
          <td><%= store.supported_locales_list.map {|l| locale_presentation(l).first }.join(', ') %></td>
          <td><%= active_badge(store.default) %></td>
          <td class="actions" data-hook="admin_stores_index_row_actions">
            <span class="d-flex justify-content-end">
              <%= link_to_edit_url spree.edit_admin_store_path(store), no_text: true if can?(:edit, store) %>

              <% if can?(:edit, store) %>
                <% btn_url = store.default? ? '#' : spree.set_default_admin_store_path(store) %>
                <% btn_class = store.default? ? 'outline-secondary disabled' : 'warning' %>
                <% btn_label = store.default? ? nil : Spree.t(:store_set_default_button) %>
                <%= link_to_with_icon('save.svg', btn_label, btn_url, no_text: true, method: (store.default? ? nil : :put), class: "btn btn-#{btn_class} btn-sm with-tip", aria: {disabled: store.default?}) %>
              <% end %>

              <%= link_to_delete store, no_text: true, url: spree.admin_store_path(store) if can?(:destroy, store) %>
            </span>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
</div>
<% else %>
  <div class="text-center no-objects-found m-5">
    <%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::Store)) %>
  </div>
<% end %>