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

{% form_theme currencyForm '@PrestaShop/Admin/TwigTemplateForm/prestashop_ui_kit.html.twig' %}

{% block form %}
  {{ form_start(currencyForm, {
    attr: {
      id: 'currency_form',
      'data-reference-url': path('admin_currencies_get_reference_data', {currencyIsoCode: 'CURRENCY_ISO_CODE'})|replace({'/CURRENCY_ISO_CODE': '{/id}'}),
      'data-languages': languages|json_encode,
      'data-translations': {
        'step.symbol': '1. Enter symbol'|trans({}, 'Admin.International.Feature'),
        'step.format': '2. Choose format'|trans({}, 'Admin.International.Feature'),
        'modal.title': 'Customize symbol and format'|trans({}, 'Admin.International.Feature'),
        'modal.apply': 'Apply'|trans({}, 'Admin.Actions'),
        'modal.cancel': 'Cancel'|trans({}, 'Admin.Actions'),
        'modal.close': 'Close'|trans({}, 'Admin.Actions'),
        'list.language': 'Language'|trans({}, 'Admin.Global'),
        'list.example': 'Example'|trans({}, 'Admin.Global'),
        'list.edit': 'Edit symbol / format'|trans({}, 'Admin.International.Feature'),
        'list.reset': 'Reset'|trans({}, 'Admin.Actions'),
        'list.reset.success': 'Your symbol and format customizations have been successfully reset for this language.'|trans({}, 'Admin.Notifications.Success'),
        'list.example.format': '{price}'|trans({}, 'Admin.International.Feature'),
        'modal.restore.title': 'Are you sure you want to restore default settings?'|trans({}, 'Admin.International.Feature'),
        'modal.restore.apply': 'Restore'|trans({}, 'Admin.Actions'),
        'modal.restore.cancel': 'Cancel'|trans({}, 'Admin.Actions'),
        'modal.restore.body': 'Restoring your currency\'s default settings will delete all the customizations you made before. Parameters will look just the same as when the currency is freshly imported.'|trans({}, 'Admin.International.Feature'),
      }|json_encode,
    },
    }) }}

    <div class="card card-currency">
      <h3 class="card-header">
        {{ 'Currency'|trans({}, 'Admin.Global') }}
      </h3>
      <div class="card-body">
        <div class="form-wrapper">
          {{ form_errors(currencyForm) }}

          {% if not currencyForm.vars.data.id is defined %}

            {{ form_row(currencyForm.selected_iso_code) }}
            <div class="form-group row type-checkbox ">
              <label for="currency_unofficial" class="form-control-label ">
                {{ 'or'|trans({}, 'Admin.Global') }}
              </label>
              {{ form_widget(currencyForm.unofficial) }}
            </div>
          {% endif %}

          {{ form_row(currencyForm.names) }}

          {% set symbolsClass = currencyForm.symbols.vars.errors|length ? '' : 'd-none' %}
          {{ form_row(currencyForm.symbols, {row_attr: {class: symbolsClass}}) }}
          {{ form_widget(currencyForm) }}
        </div>
      </div>

      <div class="card-footer">
        <div class="card-footer-left">
          <a href="{{ path('admin_currencies_index') }}" class="btn btn-outline-secondary">
            {{ 'Cancel'|trans({}, 'Admin.Actions') }}
          </a>

          {% if currencyForm.vars.data.id is defined and not currencyForm.vars.data.unofficial %}
            <button type="button" id="currency_reset_default_settings" class="btn btn-outline-secondary card-currency-reset">
              <i class="material-icons">refresh</i>
              {{ 'Restore default settings'|trans({}, 'Admin.International.Feature') }}
            </button>
          {% endif %}
        </div>

        <button type="submit" class="btn btn-primary" id="save-button">{{ 'Save'|trans({}, 'Admin.Actions') }}</button>
      </div>
    </div>
  {{ form_end(currencyForm) }}

  {% if languageDataError is defined and languageDataError %}
    <div class="card">
      <div class="card-body">
        <div class="alert alert-danger">
          {{ 'Could not display symbol and format customization:'|trans({}, 'Admin.International.Notification') }} {{ languageDataError }}
        </div>
      </div>
    </div>
  {% else %}
    <!-- Modal -->
    <div class="modal fade" id="currency_loading_data_modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
      <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLongTitle">{{ 'Loading currency data'|trans({}, 'Admin.International.Feature') }}</h5>
          </div>
          <div class="modal-body">
            {{ 'Please wait while currency data is being loaded'|trans({}, 'Admin.International.Feature') }}
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary spinner">{{ 'Close'|trans({}, 'Admin.Actions') }}</button>
          </div>
        </div>
      </div>
    </div>
  {% endif %}
{% endblock %}
