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

{% extends '@PrestaShop/Admin/layout.html.twig' %}

{% block session_alert %}
  {{ parent() }}

  {# Display generated client secrets passed by session #}
  {% if app.session.flashbag.peek('client_secret')|length() > 0 %}
    {% for clientSecret in app.session.flashbag.get('client_secret') %}
      <div class="alert alert-success d-print-none" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
          <span aria-hidden="true"><i class="material-icons">close</i></span>
        </button>
        <div class="alert-text">
          {{ 'Client secret:'|trans({}, 'Admin.Advparameters.Feature') }} {{ clientSecret }}
          <a href="#" class="copy-secret-to-clipboard" data-secret="{{ clientSecret|trim }}">
            {{ 'Copy'|trans({}, 'Admin.Actions') }}
            <i class="material-icons">content_copy</i>
          </a>
        </div>
      </div>
    {% endfor %}
  {% endif %}
{% endblock %}

{% block content %}
  {% block api_client_form_block %}
    {{ form_start(apiClientForm, {attr: {'data-id': apiClientId|default(0)}}) }}

    <div class="card">
      <h3 class="card-header">
        {{ 'API client'|trans({}, 'Admin.Advparameters.Feature') }}
      </h3>

      <div class="card-body">
        <div class="form-wrapper">
          {{ form_widget(apiClientForm) }}
        </div>
      </div>

      <div class="card-footer">
        <a href="{{ path('admin_api_index') }}" class="btn btn-outline-secondary">
          {{ 'Cancel'|trans({}, 'Admin.Actions') }}
        </a>
        <div class="float-right">
          {% block form_submit_buttons %}
            <button type="submit" class="btn btn-primary">
              {{ 'Generate client secret and save'|trans({}, 'Admin.Advparameters.Feature') }}
            </button>
          {% endblock %}
        </div>
      </div>
    </div>

    {{ form_end(apiClientForm) }}
  {% endblock %}
{% endblock %}

{% block javascripts %}
  {{ parent() }}
  <script src="{{ asset('themes/new-theme/public/api_client_form.bundle.js') }}"></script>
{% endblock %}
