{{!
  Copyright IBM Corp. 2016, 2025
  SPDX-License-Identifier: BUSL-1.1
}}

<PkiPaginatedList @backend={{@backend}} @listRoute="keys.index" @list={{@keys}} @hasConfig={{@hasConfig}}>
  <:actions>
    {{#if @canImportKeys}}
      <ToolbarLink @route="keys.import" @model={{@backend}} @type="upload" data-test-pki-key-import>
        Import
      </ToolbarLink>
    {{/if}}
    {{#if @canGenerateKeys}}
      <ToolbarLink @route="keys.create" @model={{@backend}} @type="add" data-test-pki-key-generate>
        Generate
      </ToolbarLink>
    {{/if}}
  </:actions>
  <:description>
    <p class="has-padding">Below is information about the private keys used by the issuers to sign certificates. While
      certificates represent a public assertion of an identity, private keys represent the private part of that identity, a
      secret used to prove who they are and who they trust.</p>
  </:description>
  <:list as |keys|>
    {{#each keys as |pkiKey|}}
      <LinkedBlock
        class="list-item-row"
        @params={{array "keys.key.details" @backend pkiKey.key_id}}
        @linkPrefix={{@mountPoint}}
      >
        <div class="level is-mobile">
          <div class="level-left">
            <div>
              <Icon @name="certificate" class="has-text-grey-light" />
              <span class="has-text-weight-semibold is-underline" data-test-key={{if pkiKey.key_name "name" "id"}}>
                {{or pkiKey.key_name pkiKey.key_id}}
              </span>
              <div class="is-flex-row has-left-margin-l has-top-margin-xs">
                {{#if pkiKey.key_name}}
                  <Hds::Badge @text={{pkiKey.key_id}} data-test-key="id" />
                {{/if}}
              </div>
            </div>
          </div>
          <div class="level-right is-flex is-paddingless is-marginless">
            <div class="level-item">
              {{#let (get @keyPermsById pkiKey.key_id) as |perms|}}
                {{#if (or perms.canRead perms.canUpdate)}}
                  <Hds::Dropdown @isInline={{true}} @listPosition="bottom-right" as |dd|>
                    <dd.ToggleIcon
                      @icon="more-horizontal"
                      @text="Manage key"
                      @hasChevron={{false}}
                      data-test-popup-menu-trigger
                    />
                    {{#if perms.canRead}}
                      <dd.Interactive
                        @route="keys.key.details"
                        @models={{array @backend pkiKey.key_id}}
                        data-test-key-menu-link="details"
                      >
                        Details
                      </dd.Interactive>
                    {{/if}}
                    {{#if perms.canUpdate}}
                      <dd.Interactive
                        @route="keys.key.edit"
                        @models={{array @backend pkiKey.key_id}}
                        data-test-key-menu-link="edit"
                      >
                        Edit
                      </dd.Interactive>
                    {{/if}}
                  </Hds::Dropdown>
                {{/if}}
              {{/let}}
            </div>
          </div>
        </div>
      </LinkedBlock>
    {{/each}}
  </:list>

  <:empty>
    <Hds::ApplicationState class="top-padding-32 is-marginless" as |A|>
      <A.Header @title="No keys yet" @titleTag="h2" data-test-empty-state-title />
      <A.Body @text="There are no keys in this PKI mount. You can generate or create one." data-test-empty-state-message />
    </Hds::ApplicationState>
  </:empty>

  <:configure>
    <Hds::ApplicationState class="top-padding-32 is-marginless" as |A|>
      <A.Header @title="PKI not configured" @titleTag="h2" data-test-empty-state-title />
      <A.Body @text={{this.notConfiguredMessage}} data-test-empty-state-message />
      <A.Footer data-test-empty-state-actions as |F|>
        <F.LinkStandalone
          @icon="chevron-right"
          @iconPosition="trailing"
          @text="Configure PKI"
          @route="configuration.create"
          @model={{@backend}}
        />
      </A.Footer>
    </Hds::ApplicationState>
  </:configure>
</PkiPaginatedList>