{{!
  Copyright (c) HashiCorp, Inc.
  SPDX-License-Identifier: BUSL-1.1
~}}

<PkiPageHeader @backend={{this.model.parentModel}} />

<PkiPaginatedList
  @backend={{this.model.parentModel.id}}
  @listRoute="roles.index"
  @list={{this.model.roles}}
  @hasConfig={{this.model.hasConfig}}
>
  <:actions>
    {{#if this.model.hasConfig}}
      <ToolbarLink @type="add" @route="roles.create" @model={{this.model.parentModel.id}} data-test-pki-role-create-link>
        Create role
      </ToolbarLink>
    {{/if}}
  </:actions>
  <:list as |roles|>
    {{#each roles as |pkiRole|}}
      <LinkedBlock
        class="list-item-row"
        @params={{array "roles.role.details" this.model.parentModel.id pkiRole.id}}
        @linkPrefix={{this.mountPoint}}
      >
        <div class="level is-mobile">
          <div class="level-left">
            <div>
              <Icon @name="user" class="has-text-grey-light" />
              <span class="has-text-weight-semibold is-underline">
                {{pkiRole.id}}
              </span>
            </div>
          </div>
          <div class="level-right is-flex is-paddingless is-marginless">
            <div class="level-item">
              <Hds::Dropdown @isInline={{true}} @listPosition="bottom-right" as |dd|>
                <dd.ToggleIcon
                  @icon="more-horizontal"
                  @text="Manage role"
                  @hasChevron={{false}}
                  data-test-popup-menu-trigger
                />
                <dd.Interactive
                  @text="Details"
                  @route="roles.role.details"
                  @models={{array this.model.parentModel.id pkiRole.id}}
                />
                <dd.Interactive
                  @text="Edit"
                  @route="roles.role.edit"
                  @models={{array this.model.parentModel.id pkiRole.id}}
                />
              </Hds::Dropdown>
            </div>
          </div>
        </div>
      </LinkedBlock>
    {{/each}}
  </:list>
  <:empty>
    <EmptyState
      @title="No roles yet"
      @message="When created, roles will be listed here. Create a role to start generating certificates."
    />
  </:empty>
  <:configure>
    <EmptyState @title="PKI not configured" @message={{this.notConfiguredMessage}}>
      <Hds::Link::Standalone
        @icon="chevron-right"
        @iconPosition="trailing"
        @text="Configure PKI"
        @route="configuration.create"
        @model={{this.model.parentModel.id}}
      />
    </EmptyState>
  </:configure>
</PkiPaginatedList>