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

<Toolbar>
  <ToolbarActions>
    {{#if @capabilities.canDelete}}
      <ConfirmAction
        @buttonText="Revoke credentials"
        class="toolbar-button"
        @buttonColor="secondary"
        @onConfirmAction={{this.revoke}}
        @confirmTitle="Revoke this?"
        @confirmMessage="Any client using these credentials will no longer be able to."
      />
      <div class="toolbar-separator"></div>
    {{/if}}
    <Hds::Copy::Button
      @text="Copy certificate"
      @textToCopy={{@credentials.certificate}}
      @onError={{(fn (set-flash-message "Clipboard copy failed. The Clipboard API requires a secure context." "danger"))}}
      class="toolbar-button"
      data-test-copy-button
    />
    <div class="toolbar-separator"></div>
    <ToolbarLink @route="credentials.index" @models={{array @scopeName @roleName}} data-test-back-to-role>
      Back to role
    </ToolbarLink>
  </ToolbarActions>
</Toolbar>

<div class="box is-shadowless is-fullwidth is-sideless">
  <InfoTableRow @label="Serial number" @value={{@credentials.serial_number}}>
    <MaskedInput @value={{@credentials.serial_number}} @displayOnly={{true}} @allowCopy={{true}} />
  </InfoTableRow>

  {{#if @credentials.private_key}}
    <InfoTableRow @label="Private key" @value={{@credentials.private_key}}>
      <div class="is-block">
        <Hds::Alert data-test-warning @type="inline" @color="warning" @class="has-bottom-margin-s" as |A|>
          <A.Title>Warning</A.Title>
          <A.Description>You will not be able to access the private key later, so please copy the information below.</A.Description>
        </Hds::Alert>
        <MaskedInput @value={{@credentials.private_key}} @name="Private key" @allowCopy={{true}} @displayOnly={{true}} />
      </div>
    </InfoTableRow>
  {{/if}}

  <InfoTableRow @label="Certificate" @value={{@credentials.certificate}}>
    <MaskedInput @value={{@credentials.certificate}} @displayOnly={{true}} @allowCopy={{true}} />
  </InfoTableRow>

  <InfoTableRow @label="CA Chain" @value={{@credentials.ca_chain}}>
    <div class="is-block">
      {{#each @credentials.ca_chain as |chain|}}
        <MaskedInput @value={{chain}} @displayOnly={{true}} @allowCopy={{true}} />
      {{/each}}
    </div>
  </InfoTableRow>
</div>