{% extends "part/import_wizard/ajax_part_upload.html" %}
{% load inventree_extras %}
{% load i18n %}
{% load static %}
{% load crispy_forms_tags %}

{% block form_alert %}
{% if form.errors %}
{% endif %}
{% if form_errors %}
<div class='alert alert-danger alert-block' role='alert'>
    {% trans "Errors exist in the submitted data" %}
</div>
{% endif %}
{% endblock form_alert %}

{% block form_content %}
        <thead>
            <tr>
                <th></th>
                <th>{% trans "Row" %}</th>
                {% for col in columns %}

                <th>
                    <input type='hidden' name='col_name_{{ forloop.counter0 }}' value='{{ col.name }}'/>
                    <input type='hidden' name='col_guess_{{ forloop.counter0 }}' value='{{ col.guess }}'/>
                    {% if col.guess %}
                    {{ col.guess }}
                    {% else %}
                    {{ col.name }}
                    {% endif %}
                </th>
                {% endfor %}
            </tr>
        </thead>
        <tbody>
             <tr></tr> {% comment %} Dummy row for javascript del_row method {% endcomment %}
            {% for row in rows %}
            <tr {% if row.errors %} style='background: #ffeaea;'{% endif %} part-select='#select_part_{{ row.index }}'>
                <td>
                    <button class='btn btn-outline-secondary btn-remove' onClick='removeRowFromBomWizard()' id='del_row_{{ row.index }}' style='display: inline; float: right;' title='{% trans "Remove row" %}'>
                            <span row_id='{{ row.index }}' class='fas fa-trash-alt icon-red'></span>
                    </button>
                </td>
                <td>
                {% add row.index 1 %}
                </td>
                {% for item in row.data %}
                <td>
                    {% if item.column.guess %}
                        {% with row_name=item.column.guess|lower %}
                        {% for field in form.visible_fields %}
                            {% if field.name == row|keyvalue:row_name %}
                                {{ field|as_crispy_field }}
                            {% endif %}
                        {% endfor %}
                        {% endwith %}
                    {% else %}
                        {{ item.cell }}
                    {% endif %}
                    <input type='hidden' name='row_{{ row.index }}_col_{{ forloop.counter0 }}' value='{{ item.cell }}'/>
                </td>
                {% endfor %}
            </tr>
            {% endfor %}
        </tbody>
{% endblock form_content %}

{% block form_buttons_bottom %}
{% endblock form_buttons_bottom %}

{% block js_ready %}
{{ block.super }}

$('.bomselect').select2({
    dropdownAutoWidth: true,
    matcher: partialMatcher,
});

$('.currencyselect').select2({
    dropdownAutoWidth: true,
});

{% endblock %}
