{% if error %}
  <div class="alert alert-danger">{{ error|raw }}</div>
{% endif %}

{# Preview #}
{% if preview %}
  <h1>{{ _t('EDIT_PREVIEW') }}</h1>
  <div class="page_preview">
    {{ bodyPreview|raw }}
  </div>
{% endif %}

<form id="ACEditor" name="ACEditor" enctype="multipart/form-data"
      action="{{ url({ handler: handler }) }}" method="POST">

  {% if passwordForEditing %}
    <input type="hidden" name="password_for_editing" value="{{ request.post['password_for_editing'] }}" />
  {% endif %}

  <input type="hidden" name="previous" value="{{ previous }}" />

  {% if preview %}
    <input type="hidden" name="body" value="{{ body|raw }}" />
  {% else %}
    {{ renderAction('aceditor', { saveButton: true, name: 'body', value: body })|raw }}
  {% endif %}

  {% if request.get.newpage is same as '1' and request.get.theme is not empty %}
    <input type="hidden" name="newpage" value="1"/>
    {% for key in [
          'theme',
          'style',
          'squelette',
          'bgimg',
          'PageFooter',
          'PageHeader',
          'PageTitre',
          'PageRapideHaut',
          'PageMenuHaut',
          'PageMenu',
          'favorite_preset'
          ] %}
      {% if request[key] is not empty %}
          <input type="hidden" name="{{key}}" value="{{request[key]}}"/>
      {% endif %}
    {% endfor %}
  {% endif %}

  {# Filled by tools/tags/handles/page/edit__ #}
  {# TODO: stop using all those edit__, and put directly the code here #}
  <div class="tags-container"></div>

  <div class="form-actions">
    {# Save Button #}
    {% set action = (not bodyPreview and config['preview_before_save']) ? 'preview' : saveValue %}
    <button type="submit" name="submit" value="{{ action }}" class="btn btn-primary">
      {{ _t('TEMPLATE_SAVE') }}
    </button>

    {# Reedit Button #}
    {% if preview %}
      <button type="submit" name="submit" value="reedit" class="btn btn-primary">
        {{ _t('TEMPLATE_REEDIT') }}
      </button>
    {% endif %}

    {# Cancel Button #}
    <a class="btn btn-default" onclick="document.location = '{{ cancelUrl }}'">
      {{ _t('TEMPLATE_CANCEL') }}
    </a>

    {# Theme Button #}
    {% if not preview %}
      <span class="theme-container">
        {# Filled by tools/template/handler/page/edit__ #}
        {# TODO: stop using all those edit__, and put directly the code here #}
      </span>
    {% endif %}
  </div>

</form>

{# They should be included outside of form tag #}
{{ include('@aceditor/aceditor-modals.twig') }}
