<div class="row">
  <div class="col-xs-12">
    <div class="page-header">
      <h1>Ingredients</h1>
    </div>

    <% if @ingredients.empty? %>
      <p>No Ingredients</p>
    <% else %>

      <% if current_user? %>
        <%= link_to 'New Ingredient', new_ingredient_path, class: 'btn btn-default' %>
      <% end %>

      <br/>

      <table class="table table-condensed table-hover">
        <thead>
        <tr>
          <th>Name</th>
          <th>USDA</th>
          <th>KCal per 100g</th>
          <th>Density (oz/cup)</th>
          <% if current_user? %>
            <th></th>
          <% end %>
        </tr>
        </thead>

        <tbody>
        <% decorate(@ingredients, IngredientDecorator).each do |ingredient| %>
          <tr>
            <td><%= link_to_if current_user?, ingredient.name, edit_ingredient_path(ingredient) %></td>
            <td><%= ingredient.ndbn_check %></td>
            <td><%= ingredient.kcal %></td>
            <td><%= ingredient.density %></td>
            <% if current_user? %>
              <td>
                <%= link_to ingredient, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-xs btn-danger' do %>
                  <span class="glyphicon glyphicon-remove"></span>
                <% end %>
              </td>
            <% end %>
          </tr>
        <% end %>
        </tbody>
      </table>
    <% end %>

    <br/>

    <% if current_user? %>
      <%= link_to 'New Ingredient', new_ingredient_path, class: 'btn btn-default' %>
    <% end %>


  </div>
</div>
