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

<Toolbar>
  <ToolbarActions>
    {{#if @capabilities.canDelete}}
      <ConfirmAction
        class="toolbar-button"
        @buttonColor="secondary"
        @onConfirmAction={{this.deleteRole}}
        @confirmTitle="Delete role?"
        @buttonText="Delete"
        data-test-pki-role-delete
      />
      <div class="toolbar-separator"></div>
    {{/if}}
    {{#if @capabilities.canGenerateCert}}
      <LinkTo
        class="toolbar-link"
        @route="roles.role.generate"
        @models={{array this.secretMountPath.currentPath @role.name}}
        data-test-pki-role-generate-cert
      >
        Generate Certificate
        <Icon @name="chevron-right" />
      </LinkTo>
    {{/if}}
    {{#if @capabilities.canSign}}
      <LinkTo
        class="toolbar-link"
        @route="roles.role.sign"
        @models={{array this.secretMountPath.currentPath @role.name}}
        data-test-pki-role-sign-cert
      >
        Sign Certificate
        <Icon @name="chevron-right" />
      </LinkTo>
    {{/if}}
    {{#if @capabilities.canEdit}}
      <LinkTo
        class="toolbar-link"
        @route="roles.role.edit"
        @models={{array this.secretMountPath.currentPath @role.name}}
        data-test-pki-role-edit-link
      >
        Edit
        <Icon @name="chevron-right" />
      </LinkTo>
    {{/if}}
  </ToolbarActions>
</Toolbar>

{{#each this.displayGroups as |fg|}}
  {{#each-in fg as |group fields|}}
    {{#if (not-eq group "default")}}
      <h3 class="is-size-4 has-text-weight-semibold has-top-margin-m">{{group}}</h3>
    {{/if}}

    {{#each fields as |field|}}
      {{#let (get @role field) as |val|}}
        {{#let (this.label field) as |label|}}
          {{#if (eq field "issuer_ref")}}
            <InfoTableRow @label={{label}} @value={{val}} @alwaysRender={{true}}>
              <LinkTo @route="issuers.issuer.details" @models={{array this.secretMountPath.currentPath val}}>
                {{val}}
              </LinkTo>
            </InfoTableRow>
          {{else if (this.isArrayField field)}}
            <InfoTableRow @label={{label}} @value={{val}} @alwaysRender={{true}} />
          {{else if (includes field (array "no_store" "no_store_metadata"))}}
            <InfoTableRow @label={{label}} @value={{not val}} @alwaysRender={{true}} />
          {{else if (eq field "custom_ttl")}}
            {{! Show either notAfter or ttl }}
            <InfoTableRow
              @label={{label}}
              @value={{or @role.not_after @role.ttl}}
              @alwaysRender={{true}}
              @formatDate={{if @role.not_after "MMM d yyyy HH:mm zzzz"}}
              @formatTtl={{@role.ttl}}
            />
          {{else}}
            <InfoTableRow
              @label={{label}}
              @value={{val}}
              @alwaysRender={{true}}
              @type={{if (this.isArrayField field) "array"}}
              @defaultShown={{this.defaultShown field}}
              @formatTtl={{includes field (array "not_before_duration" "max_ttl")}}
            />
          {{/if}}
        {{/let}}
      {{/let}}
    {{/each}}
  {{/each-in}}
{{/each}}