{% load i18n %}
{% load inventree_extras %}

{% block pre_form_content %}

{% endblock %}

<form method="post" action='' class='js-modal-form' enctype="multipart/form-data">
  {% csrf_token %}
  {% load crispy_forms_tags %}

  <input type='hidden' name='stock_action' value='{{ stock_action }}'/>
  
  <table class='table table-condensed table-striped' id='stock-table'>
      <tr>
          <th>{% trans "Stock Item" %}</th>
          <th>{% trans "Location" %}</th>
          <th>{% trans "Quantity" %}</th>
          {% if edit_quantity %}
          <th>{{ stock_action_title }}</th>
          {% endif %}
          <th></th>
      </tr>
      {% for item in stock_items %}
      <tr id='stock-row-{{ item.id }}' class='error'>
          <td>{% include "hover_image.html" with image=item.part.image hover=True %}
            {{ item.part.full_name }} <small><i>{{ item.part.description }}</i></small></td> 
          <td>{{ item.location.pathstring }}</td> 
          <td>{% decimal item.quantity %}</td>
          <td>
            {% if edit_quantity %}
            <input class='numberinput'
              min='0'
              {% if stock_action == 'take' or stock_action == 'move' %} max='{{ item.quantity }}' {% endif %}
              value='{% decimal item.new_quantity %}' type='number' name='stock-id-{{ item.id }}' id='stock-id-{{ item.id }}'/>
            {% if item.error %}
            <br><span class='help-inline'>{{ item.error }}</span>
            {% endif %}
            {% else %}
            <input type='hidden' name='stock-id-{{ item.id }}' value='{{ item.new_quantity }}'/>
            {% endif %}  
          </td>
          <td><button class='btn btn-default btn-remove' onclick='removeStockRow()' id='del-{{ item.id }}' title='Remove item' type='button'><span row='stock-row-{{ item.id }}' class='fas fa-trash-alt icon-red'></span></button></td>
      </tr>
      {% endfor %}
    </table>
  
  {% crispy form %}

</form>