{% extends "wiki/base.html" %}
{% from "includes/error_list.html" import errorlist %}
{% from 'wiki/includes/page_buttons.html' import page_buttons with context %}
{% from "includes/common_macros.html" import content_editor %}
{% set title = _('Create a New {title}')|fe(title=('Template' if is_template else 'Article')) %}
{% block title %}{{ page_title(title) }}{% endblock %}
{% set classes = 'new' %}
{% block bodyclass %}new{% if is_template %} is-template{% endif %}{% endblock %}

{% block site_css %}
    {{ super() }}
    {{ css('wiki-edit') }}
    {{ css('jquery-ui') }}
{% endblock %}

{% block content %}
    <article id="new-document">
    {{ errorlist(document_form) }}
    {{ errorlist(revision_form) }}
    <form id="wiki-page-edit" class="editing" method="post" action="">
      {{ csrf() }}
      <fieldset>
      <header id="article-head">

        {{ page_buttons(wiki, document, discard_href, 'top') }}

        {{ document_form.category|safe }}

        <div class="title">
            <h1><span class="action">{{ ('Create a ') }}</span><em>{{ _('New Document') }}</em></h1>
        </div>

        <ul class="metadata">
            <li class="clear">
                <label for="id_title">{{_('Title:')}}</label>
                {{ document_form.title | safe }}
            </li>
            <li class="clear">
                <label for="id_slug"><dfn title="{{_('URL segment that identifies the page')}}">{{_('Slug:')}}</dfn></label>
                {{ document_form.slug | safe }}
            </li>
          {% if parent_slug and not is_template %}
            <li class="clear"><label>{{_('Parent:')}}</label>
                <a href="{{ parent_path }}" class="metadataDisplay" target="_blank">{{ parent_slug }}</a></li>
          {% endif %}
          {% if is_template %}
            <input type="hidden" name="toc_depth" value="0" />
          {% else %}
            {% include 'wiki/includes/document_toc_field.html' %}
          {% endif %}
        </ul>
        <input type="hidden" name="parent_topic" value="{{ parent_id | safe }}" />
        <div class="hidden" id="parentSlugPrefix">{{ parent_slug | safe }}</div>

      </header>

      {% include 'wiki/includes/guide_links.html' %}

      {% if is_template %}
        {{ revision_form.content|safe }}
        <div id="ace_content" class="editor-container"></div>
      {% else %}
        <div class="ckeditor-container editor-container">
          {{ revision_form.content|safe }}
        </div>
      {% endif %}

      {% include 'wiki/includes/revision_comment.html' %}

      {% include 'wiki/includes/review_tags.html' %}

      <section id="page-tags" class="page-tags wiki-block">

          <h3><i aria-hidden="true" class="icon-tags"></i>{{ _('Tags') }}</h3>

        <input id="tagit_tags" type="text" name="tags" value="{% for tag in initial_tags %}{{ tag.name }},{% endfor %}" maxlength="255" />
      </section>


    </fieldset>

      <section class="wiki-block">
        {{ page_buttons(wiki, document, discard_href, 'bottom') }}
      </section>
    </form>

    {% include 'attachments/includes/attachment_list.html' %}

    </article>

{% endblock %}

{% block site_js %}
    {{ super() }}
    {{ js('jquery-ui') }}

    {% include 'wiki/includes/tag_suggestions.html' %}

    {% if is_template %}
      {% include 'wiki/includes/ace_scripts.html' %}
    {% else %}
      {% include 'wiki/includes/ckeditor_scripts.html' %}
    {% endif %}
    {{ js('wiki-edit') }}

{% endblock %}
