<div class='admin-controls'>
  <div class='span15'>
    <ul class="nav nav-pills">
      <li>{{#link-to 'adminFlags.active'}}{{i18n admin.flags.active}}{{/link-to}}</li>
      <li>{{#link-to 'adminFlags.old'}}{{i18n admin.flags.old}}{{/link-to}}</li>
    </ul>
  </div>
</div>

{{#if model.loading}}
  <div class='admin-loading'>{{i18n loading}}</div>
{{else}}
  {{#if model.length}}
    <table class='admin-flags'>
      <thead>
        <tr>
          <th class='user'></th>
          <th class='excerpt'></th>
          <th class='flaggers'>{{i18n admin.flags.flagged_by}}</th>
          <th class='last-flagged'></th>
          <th class='action'></th>
        </tr>
      </thead>
      <tbody>
        {{#each flaggedPost in content}}
        <tr {{bindAttr class="flaggedPost.extraClasses"}}>

          <td class='user'>{{#if flaggedPost.user}}{{#link-to 'adminUser' flaggedPost.user}}{{avatar flaggedPost.user imageSize="small"}}{{/link-to}}{{/if}}</td>

          <td class='excerpt'>{{#if flaggedPost.topicHidden}}<i title='{{i18n topic_statuses.invisible.help}}' class='icon icon-eye-close'></i> {{/if}}<h3><a href='{{unbound flaggedPost.url}}'>{{flaggedPost.title}}</a></h3><br>{{{flaggedPost.excerpt}}}
          </td>

          <td class='flaggers'>
            <table>
              {{#each flaggedPost.flaggers}}
              <tr>
                <td>
                  {{#link-to 'adminUser' this.user}}{{avatar this.user imageSize="small"}} {{/link-to}}
                </td>
                <td>
                  {{date this.flaggedAt}}
                </td>
                <td>
                  {{this.flagType}}
                </td>
              </tr>
              {{/each}}
            </table>
          </td>

        </tr>

          {{#each flaggedPost.messages}}
            <tr>
              <td></td>
              <td class='message'>
                <div>
                  {{#link-to 'adminUser' user}}{{avatar user imageSize="small"}}{{/link-to}}
                  {{message}}
                  {{#unless bySystemUser}}
                    <a href="{{unbound permalink}}"><button class='btn'><i class="icon-reply"></i> {{i18n admin.flags.view_message}}</button></a>
                  {{/unless}}
                </div>
              </td>
              <td></td>
              <td></td>
            </tr>
          {{/each}}

        <tr>
            <td colspan="4" class="action">
            {{#if adminActiveFlagsView}}
              {{#if flaggedPost.postHidden}}
                <button title='{{i18n admin.flags.disagree_unhide_title}}' class='btn' {{action disagreeFlags flaggedPost}}><i class="icon-thumbs-down"></i>  {{i18n admin.flags.disagree_unhide}}</button>
                <button title='{{i18n admin.flags.defer_title}}' class='btn' {{action deferFlags flaggedPost}}><i class="icon-external-link"></i> {{i18n admin.flags.defer}}</button>
              {{else}}
                <button title='{{i18n admin.flags.agree_hide_title}}' class='btn' {{action agreeFlags flaggedPost}}><i class="icon-thumbs-up"></i> {{i18n admin.flags.agree_hide}}</button>
                <button title='{{i18n admin.flags.disagree_title}}' class='btn' {{action disagreeFlags flaggedPost}}><i class="icon-thumbs-down"></i> {{i18n admin.flags.disagree}}</button>
              {{/if}}

              {{#if flaggedPost.canDeleteAsSpammer}}
                <button title='{{i18n admin.flags.delete_spammer_title}}' class="btn" {{action deleteSpammer flaggedPost}}><i class="icon icon-warning-sign"></i> {{i18n flagging.delete_spammer}}</button>
              {{/if}}

              <button title='{{i18n admin.flags.delete_post_title}}' class='btn' {{action deletePost flaggedPost}}><i class="icon-trash"></i> {{i18n admin.flags.delete_post}}</button>
            {{/if}}
            </td>
        </tr>

        {{/each}}

      </tbody>
    </table>
    {{#if view.loading}}
      <div class='admin-loading'>{{i18n loading}}</div>
    {{/if}}

  {{else}}
    <p>{{i18n admin.flags.no_results}}</p>
  {{/if}}
{{/if}}
