<div class='container'>
  {{custom-html "top"}}
  {{global-notice}}
  {{discourse-banner user=currentUser banner=site.banner overlay=view.hasScrolled hide=errorLoading}}
</div>

{{#if postStream.loaded}}
  {{#if postStream.firstPostPresent}}
    <div id='topic-title'>
      <div class='container'>

        <div class="title-wrapper">
          {{#if editingTopic}}
            {{#if isPrivateMessage}}
              <span class="private-message-glyph">{{fa-icon "envelope"}}</span>
              {{autofocus-text-field id='edit-title' value=buffered.title maxLength=maxTitleLength}}
            {{else}}
              {{autofocus-text-field id='edit-title' value=buffered.title maxLength=maxTitleLength}}
              <br>
              {{category-chooser valueAttribute="id" value=buffered.category_id source=buffered.category_id}}
            {{/if}}

            {{plugin-outlet "edit-topic"}}

            {{d-button action="finishedEditingTopic" class="btn-primary btn-small no-text" icon="check"}}
            {{d-button action="cancelEditingTopic" class="btn-small no-text" icon="times"}}
          {{else}}
            <h1>
              {{#unless is_warning}}
                <span class="private-message-glyph">{{fa-icon "envelope"}}</span>
              {{/unless}}

              {{#if details.loaded}}
                {{topic-status topic=model}}
                <a href='{{unbound url}}' {{action "jumpTop"}}>
                  {{{fancy_title}}}
                </a>
              {{/if}}

              {{#if details.can_edit}}
                <a href {{action "editTopic"}} class='edit-topic' title='{{i18n 'edit'}}'>{{fa-icon "pencil"}}</a>
              {{/if}}
            </h1>

            {{#unless isPrivateMessage}}
              {{topic-category topic=model}}
            {{/unless}}
          {{/if}}
        </div>
        {{plugin-outlet "topic-title"}}
      </div>
    </div>
  {{/if}}

  <div class="container posts">

    {{view "selected-posts"}}

    <div class="row">
      <section class="topic-area" id='topic' data-topic-id='{{unbound id}}'>
        <div class='posts-wrapper'>

          {{render 'topic-progress'}}

          {{loading-spinner condition=postStream.loadingAbove}}

          {{#unless postStream.loadingFilter}}
            {{cloaked-collection itemViewClass="post"
                                 idProperty="post_number"
                                 defaultHeight="200"
                                 content=postStream.posts
                                 slackRatio="15"
                                 loadingHTML=""
                                 preservesContext="true"
                                 uncloakDefault="true"
                                 offsetFixedTop="header"
                                 offsetFixedBottom="#reply-control"}}
          {{/unless}}

          {{loading-spinner condition=postStream.loadingBelow}}
        </div>
        <div id='topic-bottom'></div>

        {{#loading-spinner condition=postStream.loadingFilter}}
          {{#if loadedAllPosts}}

            {{view 'topic-closing' topic=model}}
            {{view 'topic-footer-buttons' topic=model}}

            {{#if details.suggested_topics.length}}
              <div id='suggested-topics'>
                <h3>{{i18n 'suggested_topics.title'}}</h3>
                <div class='topics'>
                  {{basic-topic-list topics=details.suggested_topics postsAction="showTopicEntrance"}}
                </div>
                <h3>{{{view.browseMoreMessage}}}</h3>
              </div>
            {{/if}}

          {{/if}}
        {{/loading-spinner}}

      </section>
    </div>

  </div>
{{else}}
  <div class='container'>
    {{#loading-spinner condition=noErrorYet}}
      {{#if notFoundHtml}}
        {{{notFoundHtml}}}
      {{else}}
        <div class="topic-error">
          <div>{{message}}</div>
          {{#if noRetry}}
            {{#unless currentUser}}
              {{d-button action="showLogin" class="btn-primary topic-retry" icon="user" label="log_in"}}
            {{/unless}}
          {{else}}
            {{d-button action="retryLoading" class="btn-primary topic-retry" icon="refresh" label="errors.buttons.again"}}
          {{/if}}
        </div>
        {{loading-spinner condition=retrying}}
      {{/if}}
    {{/loading-spinner}}
  </div>
{{/if}}

{{render "share"}}

{{#if currentUser.enable_quoting}}
  {{render "quote-button"}}
{{/if}}

{{#if currentUser.canManageTopic}}
  {{show-topic-admin show="showTopicAdminMenu"}}
  {{render "topic-admin-menu"}}
{{/if}}
