{% extends "admin/base_site.html" %}
{% load i18n admin_urls static %}

{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% translate 'Home' %}</a>
&rsaquo; <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_config.verbose_name }}</a>
&rsaquo; <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>
&rsaquo; {% translate 'Import Mapping' %}
</div>
{% endblock %}

{% block content %}
<div id="content-main">
    <form method="post" action="{{ action_url }}">
        {% csrf_token %}
        <input type="hidden" name="file_path" value="{{ file_path }}">
        <input type="hidden" name="tenant" value="{{ tenant_id }}">
        
        <fieldset class="module aligned">
            <h2>{% translate "Map CSV Columns to Model Fields" %}</h2>
            <div class="description">
                Select which CSV column matches each model field. Leave blank to skip.
            </div>

            {% for field_name, verbose_name in model_fields %}
            <div class="form-row">
                <div>
                    <label for="id_map_{{ field_name }}">{{ verbose_name }}:</label>
                    <select name="map_{{ field_name }}" id="id_map_{{ field_name }}">
                        <option value="">-- {% translate "Skip" %} --</option>
                        {% for header in headers %}
                        <option value="{{ header }}" {% if header|lower == field_name|lower or header|lower == verbose_name|lower %}selected{% endif %}>
                            {{ header }}
                        </option>
                        {% endfor %}
                    </select>
                </div>
            </div>
            {% endfor %}
        </fieldset>

        <div class="submit-row">
            <input type="submit" value="{% translate 'Preview Import' %}" class="default" name="_preview">
        </div>
    </form>
</div>
{% endblock %}