<% if @categories.blank? %>
<div class="callout callout-warning">
  <h4>Brak wpisów</h4>
  <p>Dla kategorii.</p>
</div>
<% else %>
  <table class="table table-bordered">
    <tbody>
      <tr>
        <th>ID</th>
        <th>Okładka</th>
        <th>Nazwa</th>
        <th>Il. podkategorii</th>
        <th>Il. produktów</th>
        <th>Il. produktów aktywnych</th>
        <th>Widoczne</th>
        <th>Data utworzenia</th>
        <th style="width: 180px">Akcje</th>
      </tr>
      <% for cat in @categories %>
      <tr<%= raw cat.active.eql?(false) ? ' style="background-color: lightcyan;"' : '' %>>
        <td><%= cat.id %></td>
        <td>
          <% unless cat.image.blank? %>
            <%= image_tag(cat.image.image.url(:small)) %>
          <% else %>
            <%= image_tag 'kaktus.png' %>
          <% end %>
        </td>
        <td><%= link_to cat.name, {controller: '/ps_admin/category', action: 'index', parent_id: cat.id} %></td>
        <td><%= raw('<span class="badge bg-green">' + cat.children.size.to_s + '</span>') %></td>
        <td><%= raw('<span class="badge bg-green">' + cat.products.size.to_s + '</span>') %></td>
        <td><%= raw('<span class="badge bg-' + (cat.active_products.size == 0 ? 'red' : 'green') + '">' + cat.active_products.size.to_s + '</span>') %></td>
        <td><%= raw cat.active.eql?(true) ? link_to(raw('<i class="fa fa-eye text-green"></i>'), {controller: '/ps_admin/category', action: 'set_active', id: cat.id,
          active: 0}, remote: true) : link_to(raw('<i class="fa fa-eye-slash text-red"></i>'),
          {controller: '/ps_admin/category', action: 'set_active', id: cat.id, active: 1}, remote: true) %></td>
        <td><%= cat.updated_at %></td>
        <td>
          <%= link_to raw('<i class="fa fa-edit"></i> Edycja'), {controller: '/ps_admin/category', action: 'edit', id: cat.id}, class: 'btn btn-xs btn-info', remote: true %>
          <%= link_to raw('<i class="fa fa-trash"></i> Usuń'), {controller: '/ps_admin/category', action: 'destroy', id: cat.id}, class: "btn btn-danger btn-xs", method: :delete, data: { confirm: 'Czy na pewno usunąć?' } %>
        </td>
      </tr>
      <% end %>
    </tbody>
  </table>
<% end %>
