{{#d-section pageClass="user-invites" tagName=""}}
  {{#if canInviteToForum}}
    {{#load-more class="user-content" selector=".user-invite-list tr" action=(action "loadMore")}}
      <section>
        <h2>{{i18n "user.invited.title"}}</h2>

        {{#if model.can_see_invite_details}}
          <div class="admin-controls invite-controls">
            <nav>
              <ul class="nav nav-pills">
                {{nav-item route="userInvited.show" routeParam="pending" i18nLabel=pendingLabel}}
                {{nav-item route="userInvited.show" routeParam="redeemed" i18nLabel=redeemedLabel}}
                {{#if canSendInviteLink}}
                  {{nav-item route="userInvited.show" routeParam="links" i18nLabel=linksLabel}}
                {{/if}}
              </ul>
            </nav>

            <div class="pull-right">
              {{d-button icon="plus" action=(route-action "showInvite") label="user.invited.create"}}
              {{#if canBulkInvite}}
                {{csv-uploader uploading=uploading}}
              {{/if}}
              {{#if showBulkActionButtons}}
                {{#if rescindedAll}}
                  {{i18n "user.invited.rescinded_all"}}
                {{else}}
                  {{d-button icon="times" action=(action "rescindAll") label="user.invited.rescind_all"}}
                {{/if}}
                {{#if reinvitedAll}}
                  {{i18n "user.invited.reinvited_all"}}
                {{else}}
                  {{d-button icon="sync" action=(action "reinviteAll") label="user.invited.reinvite_all"}}
                {{/if}}
              {{/if}}
            </div>
          </div>
        {{/if}}

        {{#if showSearch}}
          <div class="user-invite-search">
            <form>{{text-field value=searchTerm placeholderKey="user.invited.search"}}</form>
          </div>
        {{/if}}

        {{#if model.invites}}
          <table class="table user-invite-list">
            <tbody>
              <tr>
                {{#if inviteRedeemed}}
                  <th>{{i18n "user.invited.user"}}</th>
                  <th>{{i18n "user.invited.redeemed_at"}}</th>
                  {{#if model.can_see_invite_details}}
                    <th>{{i18n "user.last_seen"}}</th>
                    <th>{{i18n "user.invited.topics_entered"}}</th>
                    <th>{{i18n "user.invited.posts_read_count"}}</th>
                    <th>{{i18n "user.invited.time_read"}}</th>
                    <th>{{i18n "user.invited.days_visited"}}</th>
                    {{#if canSendInviteLink}}
                      <th>{{i18n "user.invited.source"}}</th>
                    {{/if}}
                  {{/if}}
                {{else if invitePending}}
                  <th colspan="1">{{i18n "user.invited.user"}}</th>
                  <th colspan="6">{{i18n "user.invited.sent"}}</th>
                {{else if inviteLinks}}
                  <th>{{i18n "user.invited.link_url"}}</th>
                  <th>{{i18n "user.invited.link_created_at"}}</th>
                  <th>{{i18n "user.invited.link_redemption_stats"}}</th>
                  <th colspan="2">{{i18n "user.invited.link_groups"}}</th>
                  <th>{{i18n "user.invited.link_expires_at"}}</th>
                  <th></th>
                {{/if}}
              </tr>
              {{#each model.invites as |invite|}}
                <tr>
                  {{#if inviteRedeemed}}
                    <td>
                      {{#link-to "user" invite.user}}{{avatar invite.user imageSize="tiny"}}{{/link-to}}
                      {{#link-to "user" invite.user}}{{invite.user.username}}{{/link-to}}
                    </td>
                    <td>{{format-date invite.redeemed_at}}</td>
                    {{#if model.can_see_invite_details}}
                      <td>{{format-date invite.user.last_seen_at}}</td>
                      <td>{{number invite.user.topics_entered}}</td>
                      <td>{{number invite.user.posts_read_count}}</td>
                      <td>{{format-duration invite.user.time_read}}</td>
                      <td>
                        <span title={{i18n "user.invited.days_visited"}}>{{html-safe invite.user.days_visited}}</span>
                          /
                        <span title={{i18n "user.invited.account_age_days"}}>{{html-safe invite.user.days_since_created}}</span>
                      </td>
                      {{#if canSendInviteLink}}
                        <td>{{html-safe invite.invite_source}}</td>
                      {{/if}}
                    {{/if}}
                  {{else if invitePending}}
                    <td>{{invite.email}}</td>
                    <td>{{format-date invite.updated_at}}</td>
                    <td>
                      {{#if invite.expired}}
                        <div>{{i18n "user.invited.expired"}}</div>
                      {{/if}}
                      {{#if invite.rescinded}}
                        {{i18n "user.invited.rescinded"}}
                      {{else}}
                        {{d-button icon="times" action=(action "rescind") actionParam=invite label="user.invited.rescind"}}
                      {{/if}}
                    </td>
                    <td>
                      {{#if invite.reinvited}}
                        <div>{{i18n "user.invited.reinvited"}}</div>
                      {{else}}
                        {{d-button icon="sync" action=(action "reinvite") actionParam=invite label="user.invited.reinvite"}}
                      {{/if}}
                    </td>
                  {{else if inviteLinks}}
                    <td>{{d-button icon="link" action=(route-action "editInvite" invite.invite_key) label="user.invited.copy_link"}}</td>
                    <td>{{format-date invite.created_at}}</td>
                    <td>{{number invite.redemption_count}} / {{number invite.max_redemptions_allowed}}</td>
                    <td colspan="2">{{ invite.group_names }}</td>
                    <td>{{raw-date invite.expires_at leaveAgo="true"}}</td>
                    <td>
                      {{#if invite.rescinded}}
                        {{i18n "user.invited.rescinded"}}
                      {{else}}
                        {{d-button icon="times" action=(action "rescind") actionParam=invite label="user.invited.rescind"}}
                      {{/if}}
                    </td>
                  {{/if}}
                </tr>
              {{/each}}
            </tbody>
          </table>
          {{conditional-loading-spinner condition=invitesLoading}}

        {{else}}
          <div class="user-invite-none">
            {{#if canBulkInvite}}
              {{html-safe (i18n "user.invited.bulk_invite.none")}}
            {{else}}
              {{i18n "user.invited.none"}}
            {{/if}}
          </div>
        {{/if}}
      </section>
    {{/load-more}}
  {{/if}}
{{/d-section}}
