{# The preparation, one step at a time — crate::pages::import_export::import::ui::ImportStep. Every button that moves between steps swaps this whole block, so each step re-states the answers the next one needs as hidden fields. The page keeps no server-side draft: what the form carries is the entire state of the preparation. #}
{% match page.step %} {#- ------------------------------------------------------------------ Step 1 — where the data is going, and how the source is laid out. ------------------------------------------------------------------ -#} {% when Step::Source %}
{# Always asked, never guessed. A data row can hold words that read exactly like column names, so deciding for the user is how a real row gets eaten as a header. #}
{{ nav.tr("import-source-mode") }}

{{ nav.tr("import-source-mode-hint") }}

{{ nav.tr("import-csv-format-hint") }}
{{ nav.tr("common-cancel") }}
{#- ------------------------------------------------------------------ Step 2a — one row per source position, pointed wherever the user says. ------------------------------------------------------------------ -#} {% when Step::Mapping with (step) %} {% include "pages/import_export/import/carried.html" %}

{{ nav.tr_args("import-mapping-heading", [("table", step.table_name.clone())]) }}

{{ nav.tr("import-mapping-hint") }}

{{ nav.tr_args("import-mapping-rows", [("rows", step.source_rows.to_string())]) }}

{% if step.has_source_names %}{% endif %} {% for row in step.rows %} {% if step.has_source_names %}{% endif %} {% endfor %}
{{ nav.tr("import-th-position") }}{{ nav.tr("import-th-source-name") }}{{ nav.tr("import-th-example") }} {{ nav.tr("import-th-destination") }}
{{ row.position }}{% if let Some(name) = row.source_name %}{{ name }}{% endif %}{{ row.example }}
{#- ------------------------------------------------------------------ Step 2b — the template generator: pick the columns, arrange them, take away the header. ------------------------------------------------------------------ -#} {% when Step::Template with (step) %} {% include "pages/import_export/import/carried.html" %}

{{ nav.tr_args("import-template-heading", [("table", step.table_name.clone())]) }}

{{ nav.tr("import-template-hint") }}

{% for row in step.rows %} {% endfor %}
{{ nav.tr("import-th-order") }} {{ nav.tr("import-th-include") }} {{ nav.tr("import-th-destination") }}
{# Both fields post in document order, so moving a row moves the generated header with it: `template_order` remembers where the unticked ones sit, `template_columns` is the header itself. #} {{ row.name }}{% if row.required %} {{ nav.tr("import-required-column") }}{% endif %}
{% if step.chosen > 0 %}

{{ nav.tr("import-template-generated") }}

{{ step.header }}
{% else %}

{{ nav.tr("import-template-nothing-chosen") }}

{% endif %}

{{ nav.tr("import-template-round-trip") }}

{# A real submit: the answer is a file. #}
{#- ------------------------------------------------------------------ Step 3 — the prepared import, exactly as it will be sent. ------------------------------------------------------------------ -#} {% when Step::Preview with (step) %} {% include "pages/import_export/import/carried.html" %} {% for value in page.form.mapping %}{% endfor %}

{{ nav.tr_args("import-preview-heading", [("table", step.table_name.clone())]) }}

{{ nav.tr("import-summary-rows") }}
{{ step.source_rows }}
{{ nav.tr("import-summary-columns-used") }}
{{ step.columns|join(", ") }}
{{ nav.tr("import-summary-ignored") }}
{% if step.ignored.is_empty() %}{% else %}{{ step.ignored|join(", ") }}{% endif %}
{{ nav.tr("import-summary-omitted") }}
{% if step.omitted.is_empty() %}{% else %}{{ step.omitted|join(", ") }}{% endif %}
{% if !step.missing_required.is_empty() %}

{{ nav.tr_args("import-summary-missing-required", [("columns", step.missing_required.join(", "))]) }}

{% endif %}
{% for column in step.columns %}{% endfor %} {% for row in step.rows %} {% for value in row %}{% endfor %} {% endfor %}
{{ column }}
{{ value }}
{% if step.hidden_rows > 0 %}

{{ nav.tr_args("import-preview-more-rows", [("rows", step.hidden_rows.to_string())]) }}

{% endif %}
{{ nav.tr("import-prepared-csv") }}

{{ nav.tr("import-prepared-csv-hint") }}

{{ step.csv }}
{# A real submit: the answer is a file. #}
{% endmatch %}