<div class='spinner'>{{i18n composer.uploading}}</div>

<div class='contents'>

  {{render composerMessages}}

  <div class='control'>
    <a href='#' class='toggler' {{action toggle bubbles=false}} title='{{i18n composer.toggler}}'></a>

    {{#if model.viewOpen}}
      <div class='control-row reply-area'>
        <div class='reply-to'>{{{model.actionTitle}}}:</div>

        {{#if model.canEditTitle}}
          <div class='form-element clearfix'>
            {{#if model.creatingPrivateMessage}}
              {{userSelector topicId=controller.controllers.topic.model.id
                             excludeCurrentUser="true"
                             id="private-message-users"
                             class="span8"
                             placeholderKey="composer.users_placeholder"
                             tabindex="1"
                             usernames=model.targetUsernames}}
            {{/if}}

            <div class="title-input">
              {{textField value=model.title tabindex="2" id="reply-title" maxlength="255" class="span8" placeholderKey="composer.title_placeholder"}}
              {{popupInputTip validation=view.titleValidation shownAt=view.showTitleTip}}
            </div>

            {{#unless model.privateMessage}}
              <div class="category-input">
                {{categoryChooser valueAttribute="id" value=model.categoryId}}
                {{popupInputTip validation=view.categoryValidation shownAt=view.showCategoryTip}}
              </div>
              {{#if model.archetype.hasOptions}}
                <button class='btn' {{action showOptions}}>{{i18n topic.options}}</button>
              {{/if}}
              {{#if model.showAdminOptions}}
                <button {{action toggleAdminOptions target="view"}} class="btn no-text" title='{{i18n composer.admin_options_title}}'><i class="icon icon-wrench"></i></button>
              {{/if}}
            {{/unless}}
          </div>

          <div class="admin-options-form">
            {{autoCloseForm autoCloseDays=model.auto_close_days}}
          </div>
        {{/if}}

        <div class='wmd-controls'>
          <div class='textarea-wrapper'>
            <div class='wmd-button-bar' id='wmd-button-bar'></div>
            {{view Discourse.NotifyingTextArea parentBinding="view" tabindex="3" valueBinding="model.reply" id="wmd-input" placeholderKey="composer.reply_placeholder"}}
            {{popupInputTip validation=view.replyValidation shownAt=view.showReplyTip}}
          </div>
          <div class='preview-wrapper'>
            <div id='wmd-preview' {{bindAttr class="hidePreview:hidden"}}></div>
          </div>
          {{#if currentUser}}
            <a href="#" {{action togglePreview}} class='toggle-preview'>{{{model.toggleText}}}</a>
            <div id='draft-status'></div>
            {{#if view.isUploading}}
              <div id="file-uploading">
                {{i18n upload_selector.uploading}} {{view.uploadProgress}}% <a id="cancel-file-upload">{{i18n cancel}}</a>
              </div>
            {{/if}}
          {{/if}}
        </div>

        {{#if currentUser}}
          <div class='submit-panel'>
            <button {{action save}} tabindex="4" {{bindAttr class=":btn :btn-primary :create model.cantSubmitPost:disabled"}}>{{model.saveText}}</button>
            <a href='#' {{action cancel}} class='cancel' tabindex="4">{{i18n cancel}}</a>
          </div>
        {{/if}}

      </div>
    {{else}}
      <div class='row'>
        <div class='span24'>
          <div class='saving-text'>
            {{#if model.createdPost}}
              {{i18n composer.saved}} <a class='permalink' href="{{unbound createdPost.url}}" {{action viewNewReply}}>{{i18n composer.view_new_post}}</a>
            {{else}}
              {{i18n composer.saving}}
            {{/if}}
          </div>
          <div class='draft-text'>
            {{i18n composer.saved_draft}}
          </div>
        </div>

      </div>
    {{/if}}

  </div>
</div>
