{{#d-section pageClass="user-invites" tagName=""}}
  {{#if canInviteToForum}}
    {{#load-more class="user-content" selector=".user-invite-list tr" action=(action "loadMore")}}
      <section>
        {{#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="expired" i18nLabel=expiredLabel}}
                {{nav-item route="userInvited.show" routeParam="redeemed" i18nLabel=redeemedLabel}}
              </ul>
            </nav>

            <div class="pull-right">
              {{d-button class="btn-default" icon="plus" action=(action "createInvite") label="user.invited.create"}}
              {{#if canBulkInvite}}
                {{d-button class="btn-default" icon="upload" action=(action "createInviteCsv") label="user.invited.bulk_invite.text"}}
              {{/if}}
              {{#if showBulkActionButtons}}
                {{#if inviteExpired}}
                  {{#if removedAll}}
                    {{i18n "user.invited.removed_all"}}
                  {{else}}
                    {{d-button icon="times" action=(action "destroyAllExpired") label="user.invited.remove_all"}}
                  {{/if}}
                {{/if}}

                {{#if invitePending}}
                  {{#if reinvitedAll}}
                    {{i18n "user.invited.reinvited_all"}}
                  {{else}}
                    {{d-button class="btn-default" icon="sync" action=(action "reinviteAll") label="user.invited.reinvite_all"}}
                  {{/if}}
                {{/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}}
          {{#if inviteRedeemed}}
            <table class="table user-invite-list">
              <thead>
                <tr>
                  <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>
                    <th>{{i18n "user.invited.invited_via"}}</th>
                  {{/if}}
                </tr>
              </thead>
              <tbody>
                {{#each model.invites as |invite|}}
                  <tr>
                    <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>
                      <td>{{html-safe invite.invite_source}}</td>
                    {{/if}}
                  </tr>
                {{/each}}
              </tbody>
            </table>
          {{else}}
            <table class="table user-invite-list">
              <thead>
                <tr>
                  <th>{{i18n "user.invited.invited_via"}}</th>
                  <th>{{i18n "user.invited.sent"}}</th>
                  <th>{{i18n "user.invited.expires_at"}}</th>
                  <th></th>
                </tr>
              </thead>
              <tbody>
                {{#each model.invites as |invite|}}
                  <tr>
                    <td class="invite-type">
                      <div class="label">{{i18n "user.invited.invited_via"}}</div>
                      {{#if invite.email}}
                        {{d-icon "envelope"}} {{invite.email}}
                      {{else}}
                        {{d-icon "link"}} {{i18n "user.invited.invited_via_link" key=invite.shortKey count=invite.redemption_count max=invite.max_redemptions_allowed}}
                      {{/if}}

                      {{#each invite.groups as |g|}}
                        <p class="invite-extra"><a href="/g/{{g.name}}">{{d-icon "users"}} {{g.name}}</a></p>
                      {{/each}}

                      {{#if invite.topic}}
                        <p class="invite-extra"><a href={{invite.topic.url}}>{{d-icon "file"}} {{invite.topic.title}}</a></p>
                      {{/if}}
                    </td>

                    <td class="invite-updated-at">
                      <div class="label">{{i18n "user.invited.sent"}}</div>
                      {{format-date invite.updated_at}}
                    </td>

                    <td class="invite-expires-at">
                      <div class="label">{{i18n "user.invited.expires_at"}}</div>
                      {{#if inviteExpired}}
                        {{raw-date invite.expires_at}}
                      {{else if invite.expired}}
                        {{i18n "user.invited.expired"}}
                      {{else}}
                        {{raw-date invite.expires_at}}
                      {{/if}}
                    </td>

                    <td class="invite-actions">
                      {{d-button class="btn-default" icon="pencil-alt" action=(action "editInvite" invite) title="user.invited.edit"}}
                      {{d-button icon="trash-alt" class="cancel" action=(action "destroyInvite" invite) title=(if invite.destroyed "user.invited.removed" "user.invited.remove")}}
                    </td>
                  </tr>
                {{/each}}
              </tbody>
            </table>
          {{/if}}

          {{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}}
  {{else}}
    <div class="alert alert-error invite-error">
      {{model.error}}
    </div>
  {{/if}}
{{/d-section}}
