<Identity::EntityNav @identityType={{this.identityType}} @model={{this.model}} />
{{#if this.model.meta.total}}
  {{#each this.model as |item|}}
    <LinkedBlock
      @params={{array "vault.cluster.access.identity.show" item.id "details"}}
      class="list-item-row"
      data-test-identity-row
    >
      <div class="columns is-mobile">
        <div class="column is-7-tablet is-10-mobile">
          <LinkTo
            @route="vault.cluster.access.identity.show"
            @models={{array item.id "details"}}
            class="is-block has-text-black has-text-weight-semibold"
            data-test-identity-link={{true}}
          >
            <Icon @name="user" class="has-text-grey-light" />
            <span class="has-text-weight-semibold">{{item.name}}</span>
          </LinkTo>
          <div class="has-text-grey is-size-8">
            {{item.id}}
          </div>
        </div>
        <div class="column is-3 is-hidden-mobile">
          {{#if item.aliases.length}}
            {{pluralize item.aliases.length "alias"}}
          {{/if}}
        </div>
        <div class="column has-text-right">
          <PopupMenu @name="identity-item" @onOpen={{action "reloadRecord" item}}>
            <Confirm as |c|>
              <nav class="menu">
                <ul class="menu-list">
                  <li class="action">
                    <LinkTo @route="vault.cluster.access.identity.show" @models={{array item.id "details"}}>
                      Details
                    </LinkTo>
                  </li>
                  {{#if (or item.isReloading item.updatePath.isPending item.aliasPath.isPending)}}
                    <li class="action">
                      <button disabled type="button" class="link button is-loading is-transparent">
                        loading
                      </button>
                    </li>
                  {{else}}
                    {{#if item.canAddAlias}}
                      <li class="action">
                        <LinkTo
                          @route="vault.cluster.access.identity.aliases.add"
                          @models={{array (pluralize this.identityType) item.id}}
                        >
                          Create alias
                        </LinkTo>
                      </li>
                    {{/if}}
                    {{#if item.canEdit}}
                      <li class="action">
                        <LinkTo @route="vault.cluster.access.identity.edit" @model={{item.id}}>
                          Edit
                        </LinkTo>
                      </li>
                      <li class="action">
                        {{#if item.disabled}}
                          <button type="button" {{action "toggleDisabled" item}} class="link">
                            Enable
                          </button>
                        {{else if (eq this.identityType "entity")}}
                          <c.Message
                            @id="{{item.id}}-disable"
                            @triggerText="Disable"
                            @message="Associated tokens will not be revoked, but cannot be used"
                            @title="Disable this?"
                            @confirmButtonText="Disable"
                            @onConfirm={{action "toggleDisabled" item}}
                            data-test-engine-disable="true"
                          />
                        {{/if}}
                      </li>
                    {{/if}}
                    {{#if item.canDelete}}
                      <li class="action">
                        <c.Message @id={{item.id}} @onConfirm={{action "delete" item}} data-test-item-delete="true" />
                      </li>
                    {{/if}}
                  {{/if}}
                </ul>
              </nav>
            </Confirm>
          </PopupMenu>
        </div>
      </div>
    </LinkedBlock>
  {{/each}}
  {{#if (gt this.model.meta.lastPage 1)}}
    <ListPagination
      @page={{this.model.meta.currentPage}}
      @lastPage={{this.model.meta.lastPage}}
      @link="vault.cluster.access.identity.index"
    />
  {{/if}}
{{else}}
  <EmptyState
    @title="No {{pluralize this.identityType}} yet"
    @message="A list of {{pluralize
      this.identityType
    }} in this namespace will be listed here. Create your first {{this.identityType}} to get started."
  >
    <LinkTo @route="vault.cluster.access.identity.create" @model={{pluralize this.identityType}} class="link">
      Create
      {{this.identityType}}
    </LinkTo>
    <DocLink @path="/vault/tutorials/auth-methods/identity">
      Learn more
    </DocLink>
  </EmptyState>
{{/if}}