<% if @category.blank? || @category.products.blank? %>
<div class="callout callout-warning">
  <h4>Brak produktów</h4>
  <p>Dla tej kategorii.</p>
</div>
<% else %>
  <table class="table table-bordered">
    <tbody>
      <tr>
        <th style="width: 50px">ID</th>
        <th style="width: 50px">-</th>
        <th>Nazwa</th>
        <th>Cena</th>
        <th>Ilość</th>
        <th style="width: 100px">Widoczne</th>
        <th style="width: 60px">Stock</th>
        <th style="width: 180px">Data utworzenia</th>
        <th style="width: 180px">Akcje</th>
      </tr>
      <% for prod in @category.products.order('name ASC') %>
      <tr>
        <td><%= prod.id %></td>
        <td>
          <% if !prod.cover_image.blank? %>
            <%= image_tag prod.cover_image.image.url(:small) %>
          <% else %>
            <%= image_tag 'kaktus.png' %>
          <% end %>
        </td>
        <td><%= link_to prod.name, {controller: '/ps_admin/product', action: 'show', id: prod.id, category_id: @category.id}, remote: true %></td>
        <td><%= '%.2f' % prod.price %></td>
        <td><%= prod.quantity %></td>
        <td><%= raw prod.active.eql?(true) ? link_to(raw('<h4><i class="fa fa-eye text-green"></i></h4>'), {controller: '/ps_admin/product', action: 'set_active', id: prod.id,
          category_id: @category.id, active: 0}, remote: true) : link_to(raw('<h4><i class="fa fa-eye-slash text-red"></i></h4>'),
          {controller: '/ps_admin/product', action: 'set_active', id: prod.id, category_id: @category.id, active: 1}, remote: true) %></td>
        <td><%= raw prod.chk_quantity.eql?(true) ? link_to(raw('<h4><i class="fa fa-check text-green"></i></h4>'), {controller: '/ps_admin/product', action: 'set_chk_quantity',
          id: prod.id, category_id: @category.id, chk_qnt: 0}, remote: true) : link_to(raw('<h4><i class="fa fa-close text-red"></i></h4>'),
          {controller: '/ps_admin/product', action: 'set_chk_quantity', id: prod.id, category_id: @category.id, chk_qnt: 1}, remote: true) %></td>
        <td><%= prod.updated_at %></td>
        <td>
          <%= link_to raw('<i class="fa fa-edit"></i> Edycja'), {controller: '/ps_admin/product', action: 'edit', id: prod.id, category_id: @category.id},
            class: 'btn btn-xs btn-info', remote: true %>
          <%= link_to raw('<i class="fa fa-trash"></i> Usuń'), {controller: '/ps_admin/product', action: 'destroy', id: prod.id, category_id: @category.id},
            class: "btn btn-danger btn-xs", method: :delete, data: { confirm: @category.id == prod.default_category_id ? "Czy na pewno usunąć produkt?\nUWAGA: Ta operacja usunie produkt ze wszystkich kategorii" : "Czy napewno usunąć produkt z tej kategorii?" }, remote: true %>
        </td>
      </tr>
      <% end %>
    </tbody>
  </table>
<% end %>
