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

<PageHeader as |p|>
  <p.top>
    <KmipBreadcrumb @scope={{this.scope}} @role={{this.role}} @currentRoute="Credentials" />
  </p.top>
  <p.levelLeft>
    <h1 class="title is-3">
      Credentials
    </h1>
  </p.levelLeft>
</PageHeader>
<Toolbar>
  <ToolbarActions>
    {{#if this.model.deletePath.canDelete}}
      <ConfirmAction
        @buttonText="Revoke credentials"
        class="toolbar-button"
        @buttonColor="secondary"
        @onConfirmAction={{this.revokeCredentials}}
        @confirmTitle="Revoke this?"
        @confirmMessage="Any client using these credentials will no longer be able to."
      />
      <div class="toolbar-separator"></div>
    {{/if}}
    <ToolbarLink @route="credentials.index" @models={{array this.scope this.role}} data-test-kmip-link-back-to-role>
      Back to role
    </ToolbarLink>
    <Hds::Copy::Button
      @text="Copy certificate"
      @textToCopy={{this.model.certificate}}
      @onError={{(fn (set-flash-message "Clipboard copy failed. The Clipboard API requires a secure context." "danger"))}}
      class="toolbar-button"
      data-test-copy-button
    />
  </ToolbarActions>
</Toolbar>
<div class="box is-shadowless is-fullwidth is-sideless">
  <InfoTableRow @label="Serial number" @value={{this.model.id}}>
    <MaskedInput @value={{this.model.id}} @displayOnly={{true}} @allowCopy={{true}} />
  </InfoTableRow>
  {{#if this.model.privateKey}}
    <InfoTableRow @label="Private key" @value={{this.model.privateKey}}>
      <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={{this.model.privateKey}} @name="Private key" @allowCopy={{true}} @displayOnly={{true}} />
      </div>
    </InfoTableRow>
  {{/if}}
  <InfoTableRow @label="Certificate" @value={{this.model.certificate}}>
    <MaskedInput @value={{this.model.certificate}} @displayOnly={{true}} @allowCopy={{true}} />
  </InfoTableRow>
  <InfoTableRow @label="CA Chain" @value={{this.model.caChain}}>
    <div class="is-block">
      {{#each this.model.caChain as |chain|}}
        <MaskedInput @value={{chain}} @displayOnly={{true}} @allowCopy={{true}} />
      {{/each}}
    </div>
  </InfoTableRow>
</div>