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

<Page::Header @title={{@role.name}}>
  <:breadcrumbs>
    <Page::Breadcrumbs @breadcrumbs={{@breadcrumbs}} />
  </:breadcrumbs>
  <:actions>
    <Hds::Dropdown as |D|>
      <D.ToggleButton @text="Manage" @color="secondary" data-test-dropdown="Manage" />
      {{#if @capabilities.canUpdate}}
        <D.Interactive @icon="edit" @route="roles.role.edit" data-test-popup-menu="Edit role">
          Edit role
        </D.Interactive>
      {{/if}}
      {{#if @capabilities.canGenerateCreds}}
        <D.Interactive @icon="key" @route="roles.role.credentials" data-test-popup-menu="Generate credentials">
          Generate credentials
        </D.Interactive>
      {{/if}}
      {{#if @capabilities.canDelete}}
        <D.Interactive
          @color="critical"
          @icon="trash"
          {{on "click" (fn (mut this.showConfirmDeleteModal) true)}}
          data-test-popup-menu="Delete role"
        >
          Delete role
        </D.Interactive>
      {{/if}}
    </Hds::Dropdown>
  </:actions>
</Page::Header>

{{#each this.displayFields as |field|}}
  <InfoTableRow
    data-test-filtered-field
    @label={{this.label field}}
    @value={{get @role field}}
    @formatTtl={{includes field (array "token_max_ttl" "token_default_ttl")}}
  />
{{/each}}

{{#if @role.generated_role_rules}}
  <div class="has-top-margin-xl" data-test-generated-role-rules>
    <h2 class="title is-4">Generated role rules</h2>
    <Hds::CodeBlock @value={{@role.generated_role_rules}} @language="ruby" @hasCopyButton={{true}} as |CB|>
      <CB.Title @tag="h3">
        Role rules
      </CB.Title>
    </Hds::CodeBlock>
  </div>
{{/if}}

{{#each this.extraFields as |field|}}
  <div class="has-top-margin-xl" data-test-extra-fields={{field.label}}>
    <h2 class="title is-4 is-marginless">{{field.label}}</h2>
    {{#each-in (get @role field.key) as |key value|}}
      <InfoTableRow @label={{key}} @value={{value}} />
    {{/each-in}}
  </div>
{{/each}}

{{#if this.showConfirmDeleteModal}}
  <ConfirmModal
    @color="critical"
    @confirmMessage="You will not be able to recover it later."
    @confirmTitle="Are you sure?"
    @onClose={{fn (mut this.showConfirmDeleteModal) false}}
    @onConfirm={{this.delete}}
  />
{{/if}}