{#
 # For the full copyright and license information, please view the
 # docs/licenses/LICENSE.txt file that was distributed with this source code.
 #}

{% trans_default_domain 'Admin.Advparameters.Feature' %}
{% form_theme importForm '@PrestaShop/Admin/TwigTemplateForm/prestashop_ui_kit.html.twig' %}

{% block import_form %}
{{ form_start(importForm, {attr: {'data-file-upload-url': importFileUploadUrl, 'data-delete-confirm-message': ('Are you sure you want to delete this entity:'|trans({}, 'Admin.Advparameters.Notification')), class: 'js-import-form'}}) }}
<div class="card">
  <h3 class="card-header">
    <i class="material-icons">import_export</i> {{ 'Import'|trans({}, 'Admin.Actions') }}
  </h3>
  <div class="card-body">
    <div class="form-wrapper">
      <div class="alert alert-info" role="alert">
        <p class="alert-text">
          {{ 'You can read information on import at:'|trans({}, 'Admin.Advparameters.Help') }}
          <a href="{{ 'https://docs.prestashop-project.org/v.8-documentation/user-guide/configuring-shop/advanced-parameters/import'|trans({}, 'Admin.Advparameters.Help') }}" target="_blank" rel="noopener noreferrer nofollow">
            {{ 'https://docs.prestashop-project.org/v.8-documentation/user-guide/configuring-shop/advanced-parameters/import'|trans({}, 'Admin.Advparameters.Help') }}
          </a>
        </p>
        <p class="alert-text">
          {{ 'Read more about the CSV format at:'|trans({}, 'Admin.Advparameters.Help') }}
          <a href="{{ 'https://en.wikipedia.org/wiki/Comma-separated_values'|trans({}, 'Admin.Advparameters.Help') }}" target="_blank" rel="noopener noreferrer nofollow">
            {{ 'https://en.wikipedia.org/wiki/Comma-separated_values'|trans({}, 'Admin.Advparameters.Help') }}
          </a>
        </p>
      </div>

      <hr>

      <div class="form-group">
        {{ form_row(importForm.entity) }}
      </div>

      <div class="alert alert-warning js-entity-alert" role="alert">
        <ul>
          <li>{{ 'Note that the Category import does not support having two categories with the same name.'|trans({}, 'Admin.Advparameters.Notification') }}</li>
          <li>{{ 'Note that you can have several products with the same reference.'|trans({}, 'Admin.Advparameters.Notification') }}</li>
        </ul>
      </div>

      <hr>

      <div class="form-group hidden-xs-up">
        {{ form_errors(importForm.csv) }}
        {{ form_widget(importForm.csv, {attr: {class: 'js-import-file-input'}}) }}
      </div>

      <div class="form-group js-file-upload-form-group">
        {{ form_label(importForm.file) }}
        <div class="row">
          <div class="col">
            {{ form_errors(importForm.file) }}
            {{ form_widget(importForm.file, {attr: {class: 'js-import-file', 'data-max-file-upload-size': maxFileUploadSize}}) }}
          </div>
          <div class="col">
            <span>{{ 'or'|trans({}, 'Admin.Global') }}</span>
            <button type="button"
                    class="btn btn-outline-primary btn-sm js-from-files-history-btn"
                    {% if importFileNames is empty %}disabled{% endif %}
            >
              <span class="badge badge-primary js-files-history-number">{{ importFileNames|length }}</span>
              {{ 'Choose from history / FTP'|trans({}, 'Admin.Advparameters.Feature') }}
            </button>
          </div>
        </div>
        <small class="form-text">{{ 'Allowed formats: .csv, .xls, .xlsx, .xlst, .ods, .ots'|trans({}, 'Admin.Advparameters.Help') }}</small>
        <small class="form-text">{{ 'Only UTF-8 and ISO 8859-1 encodings are allowed'|trans({}, 'Admin.Advparameters.Help') }}</small>
        <small class="form-text">{{ 'You can also upload your file via FTP to the following directory: %s .'|trans({'%s': importDirectory}, 'Admin.Advparameters.Help') }}</small>
      </div>

      <div class="alert alert-danger d-none js-import-file-error" role="alert">
        <p class="alert-text">
          <strong class="js-file-data"></strong>: <span class="js-error-message"></span>
        </p>
      </div>

      <div class="alert alert-success d-none js-import-file-alert" role="alert">
        <button type="button"
                class="close btn btn-outline-secondary js-change-import-file-btn"
                aria-label="{{ 'Change'|trans({}, 'Admin.Actions') }}"
        >
          <span aria-hidden="true"><i class="material-icons">edit</i></span>
        </button>
        <p class="alert-text js-import-file"></p>
      </div>

      {% block import_file_history_block %}
        {{ include('@PrestaShop/Admin/Configure/AdvancedParameters/Blocks/import_file_history.html.twig') }}
      {% endblock %}

      <hr>
      {{ form_row(importForm.iso_lang) }}
      {{ form_row(importForm.separator) }}
      {{ form_row(importForm.multiple_value_separator) }}
      <hr>
      {{ form_label(importForm.submitImportFile) }}

      {# This is done so importForm.submitImportFile is not rendered, as it's defined via plain HTML instead #}
      {% do importForm.submitImportFile.setRendered %}
      {{ form_widget(importForm) }}
    </div>
  </div>
  <div class="card-footer">
    <div class="d-flex justify-content-end">
      <button class="btn btn-primary" name="{{ importForm.submitImportFile.vars.name }}">
        {{ importForm.submitImportFile.vars.label }}
        <i class="material-icons rtl-flip">navigate_next</i>
      </button>
    </div>
  </div>
</div>
{{ form_end(importForm) }}
{% endblock %}
