{{#if content}}
  {{#if loaded}}

    {{#if view.firstPostLoaded}}
    <div id='topic-title'>
      <div class='container'>
        <div class='inner'>
          {{#if view.showFavoriteButton}}
            <a {{bindAttr class=":star view.topic.starred:starred"}} {{action toggleStar}} href='#' {{bindAttr title="favoriteTooltip"}}></a>
          {{/if}}
          {{#if view.editingTopic}}
            <input id='edit-title' type='text' {{bindAttr value="view.topic.title"}} autofocus>
            {{view Discourse.ComboboxViewCategory valueAttribute="name" contentBinding="Discourse.site.categories" sourceBinding="view.topic.categoryName"}}
            <button class='btn btn-primary btn-small' {{action finishedEdit target="view"}}><i class='icon-ok'></i></button>
            <button class='btn btn-small' {{action cancelEdit target="view"}}><i class='icon-remove'></i></button>
          {{else}}
            <h1>
              {{#if view.topic.fancy_title}}
                {{view Discourse.TopicStatusView topicBinding="view.topic"}}
                <a href='{{unbound view.topic.url}}'>{{{view.topic.fancy_title}}}</a>
              {{else}}
                {{#if view.topic.errorLoading}}
                  {{view.topic.errorTitle}}
                {{else}}
                  {{i18n topic.loading}}
                {{/if}}
              {{/if}}
              {{boundCategoryLink category}}

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

    <div class="container posts">

      {{view Discourse.SelectedPostsView}}
      <div class="row">
        <section class="topic-area" id='topic' data-topic-id='{{unbound id}}'>
          <div class='posts-wrapper'>
            <div id='topic-progress-wrapper'>
              <nav id='topic-progress' title="{{i18n topic.progress.title}}" {{bindAttr class="hideProgress:hidden"}}>
                <button id='jump-top' title="{{i18n topic.progress.jump_top}}" {{action jumpTop}}><i class="icon-circle-arrow-up"></i></button>
                <div class='nums'>
                  <h4 title="{{i18n topic.progress.current}}">{{view.progressPosition}}</h4> <span>{{i18n of_value}}</span> <h4>{{filtered_posts_count}}</h4>
                </div>
                <button id='jump-bottom' title="{{i18n topic.progress.jump_bottom}}" {{action jumpBottom}}><i class="icon-circle-arrow-down"></i></button>
                <div class='bg'>&nbsp;</div>
              </nav>
            </div>

            {{#if loadingAbove}}
              <div class='spinner'>{{i18n loading}}</div>
            {{/if}}

            {{collection itemViewClass="Discourse.PostView" contentBinding="content.posts" topicViewBinding="view"}}

            {{#if loadingBelow}}
              <div class='spinner'>{{i18n loading}}</div>
            {{/if}}
          </div>
          <div id='topic-bottom'></div>

          {{#if loading}}
            {{#unless loadingBelow}}
              <div class='spinner small'>{{i18n loading}}</div>
            {{/unless}}
          {{else}}
            {{#if view.fullyLoaded}}
              {{view Discourse.TopicFooterButtonsView topicBinding="controller.content"}}

              {{#if controller.content.suggested_topics.length}}
                <div id='suggested-topics'>

                  <h3>{{i18n suggested_topics.title}}</h3>

                  <div class='topics'>
                    <table id="topic-list">
                      <tr>
                        <th>
                          {{i18n topic.title}}
                        </th>
                        <th>{{i18n category_title}}</th>
                        <th class='num'>{{i18n posts}}</th>
                        <th class='num'>{{i18n likes}}</th>
                        <th class='num'>{{i18n views}}</th>
                        <th class='num activity' colspan='2'>{{i18n activity}}</th>
                      </tr>

                    {{each controller.content.suggested_topics itemTagName="tr" itemViewClass="Discourse.SuggestedTopicView"}}
                    </table>
                  </div>
                  <br/>
                  <h3>{{{unbound view.browseMoreMessage}}}</h3>
                </div>
              {{/if}}
            {{/if}}
          {{/if}}


        </section>
      </div>

    </div>

  {{else}}
    {{#if message}}
      <div class='container'>
        <div class='message'>

          <h2>{{message}}</h2>

          <p>
            {{#linkTo list.latest}}{{i18n topic.back_to_list}}{{/linkTo}}
        </div>
      </div>
    {{else}}
      <div class='container'>
        <div class='spinner'>{{i18n loading}}</div>
      </div>
    {{/if}}
  {{/if}}
{{/if}}

<div id='topic-filter' style='display: none'>
  {{filterDesc}}
  <a href='#' {{action cancelFilter}}>{{i18n topic.filters.cancel}}</a>
</div>

{{render share}}
{{render quoteButton}}

{{#if Discourse.currentUser.staff}}
  {{render topicAdminMenu content}}
{{/if}}
