<PageHeader as |p|>
  <p.top>
    <KeyValueHeader
      @baseKey={{hash display=this.model.id id=this.model.idForNav}}
      @path="vault.cluster.secrets.backend.list"
      @mode={{this.mode}}
      @root={{this.root}}
      @showCurrent={{true}}
    />
  </p.top>
  <p.levelLeft>
    <h1 class="title is-3" data-test-secret-header="true">
      PKI Certificate
    </h1>
  </p.levelLeft>
</PageHeader>
{{#if (eq this.model.canParse false)}}
  <AlertBanner
    @type="info"
    @message="There was an error parsing the certificate's metadata. As a result, Vault cannot display the common name or the issue and expiration dates. This will not interfere with the certificate's functionality."
    data-test-warning
  />
{{/if}}
<div class="box is-fullwidth is-sideless is-paddingless is-marginless">
  <MessageError @model={{this.model}} />
  {{#each this.model.attrs as |attr|}}
    {{#if (eq attr.type "object")}}
      <InfoTableRow
        data-test-table-row
        @label={{capitalize (or attr.options.label (humanize (dasherize attr.name)))}}
        @value={{stringify (get this.model attr.name)}}
      />
    {{else}}
      {{#if (and attr.options.masked (get this.model attr.name))}}
        <InfoTableRow
          data-test-table-row
          @label={{capitalize (or attr.options.label (humanize (dasherize attr.name)))}}
          @value={{get this.model attr.name}}
        >
          <MaskedInput @value={{get this.model attr.name}} @displayOnly={{true}} @allowCopy={{true}} />
        </InfoTableRow>
      {{else if (and (get this.model attr.name) (or (eq attr.name "issueDate") (eq attr.name "expiryDate")))}}
        <InfoTableRow
          data-test-table-row
          @label={{capitalize (or attr.options.label (humanize (dasherize attr.name)))}}
          @value={{date-format (get this.model attr.name) "MMM dd, yyyy hh:mm:ss a" isFormatted=true}}
        />
      {{else if (eq attr.name "revocationTime")}}
        <InfoTableRow
          data-test-table-row
          @label={{capitalize (or attr.options.label (humanize (dasherize attr.name)))}}
          @value={{date-format (get this.model attr.name) "MMM dd, yyyy hh:mm:ss a"}}
        />
      {{else}}
        <InfoTableRow
          data-test-table-row
          @label={{capitalize (or attr.options.label (humanize (dasherize attr.name)))}}
          @value={{get this.model attr.name}}
        />
      {{/if}}
    {{/if}}
  {{/each}}
</div>

<div class="field is-grouped is-grouped-split box is-fullwidth is-bottomless">
  <div class="field is-grouped">
    <div class="control">
      <CopyButton
        @clipboardText={{this.model.toCreds}}
        @class="button is-primary"
        @buttonType="button"
        @success={{action (set-flash-message "Credentials copied!")}}
      >
        Copy credentials
      </CopyButton>
    </div>
    <div class="control">
      <LinkTo @route="vault.cluster.secrets.backend.list-root" @query={{hash tab="cert"}} class="button">
        Back
      </LinkTo>
    </div>
  </div>
  {{#if (and (not this.model.revocationTime) this.model.canRevoke)}}
    <ConfirmAction
      @buttonClasses="button"
      @onConfirmAction={{action "delete"}}
      @confirmTitle="Revoke this cert?"
      @confirmMessage="Any services using this cert may be affected."
      @confirmButtonText="Revoke"
    >
      Revoke
    </ConfirmAction>
  {{/if}}
</div>