{% extends 'course/course-show.html.twig' %}

{% block title %}{% if thread %}{{'course.thread.form.edit'|trans}}{% else %}{{'course.thread.form.create'|trans}}{% endif %} - {{ parent() }}{% endblock %}
{% set thread = thread|default(null) %}
{% do script(['libs/es-ckeditor/ckeditor.js','libs/jquery-validation.js','app/js/course/thread-form/index.js'])%}

{% set nav = type %}

{% block detail_content %}

  <form id="thread-form" class="form-vertical" method="post"
    {% if thread %}
      action="{{ path('course_thread_edit', {courseId:course.id, threadId:thread.id}) }}"
    {% else %}
      action="{{ path('course_thread_create', {courseId:course.id}) }}"
      {% endif %}
    >

    <div class="form-group">
      <div class="controls">
        {% set placeholder = type == 'question' ? 'course.thread.form.question.placeholder'|trans : 'course.thread.form.placeholder'|trans %}
        {{ form_widget(form.title, {attr:{class:'form-control', placeholder:placeholder, 'data-display':'course.thread.form.placeholder'|trans}}) }}
      </div>
    </div>

    <div class="form-group">
      <div class="controls">
        {{
          form_widget(
            form.content, {
              attr:{
                class:'form-control',
                rows:15,
                'data-display':'course.thread.form.content'|trans,
                'data-image-upload-url': path(
                  'editor_upload', {
                    token:upload_token('course')
                  }
                ),
                'data-image-download-url': path(
                  'editor_download', {
                    token:upload_token('course')
                  }
                )
              }
            }
          )
        }}
      </div>
    </div>
    {{ render(controller('AppBundle:File/Attachment:formFields', {targetType: 'course.thread', targetId: thread.id|default(0)}, {'showLabel':false})) }}
    <div class="form-group clearfix">
      <div class="controls pull-right">
        {{ form_rest(form) }}
        {% if thread %}
          <a href="{{ path('course_thread_show', {courseId:thread.courseId, threadId:thread.id}) }}" class="btn btn-link">{{'form.btn.cancel'|trans}}</a>
          <button type="button" class="btn btn-primary js-btn-thread-save">{{'form.btn.save'|trans}}</button>
        {% else %}
          <a href="{{ path('my_course_show', {id: course.id, tab: type, type: type}) }}" class="btn btn-link">{{'form.btn.cancel'|trans}}</a>
          <button type="button" class="btn btn-primary js-btn-thread-save">{{'form.btn.reply'|trans}}</button>
        {% endif  %}
      </div>
    </div>
    <input type="hidden" name="courseSetId" value="{{ course.courseSetId }}">
    <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">
  </form>
{% endblock %}
