<PageHeader as |p|>
  <p.top>
    <KeyValueHeader
      @baseKey={{hash id=this.id}}
      @path="vault.cluster.secrets.backend.list"
      @mode="show"
      @showCurrent={{true}}
      @root={{this.backendCrumb}}
    />
  </p.top>
  <p.levelLeft>
    <h1 class="title is-3">
      {{this.id}}
    </h1>
  </p.levelLeft>
</PageHeader>
{{! Tabs }}
<div class="tabs-container box is-bottomless is-marginless is-fullwidth is-paddingless">
  <nav class="tabs">
    <ul>
      <LinkTo @route="vault.cluster.secrets.backend.show" @model={{this.id}} data-test-secret-tab>
        Secret
      </LinkTo>
      <LinkTo @route="vault.cluster.secrets.backend.metadata" @model={{this.id}}>
        Metadata
      </LinkTo>
    </ul>
  </nav>
</div>

<Toolbar>
  {{! You must have update on metadata, create is not enough. }}
  {{#if this.model.canUpdateMetadata}}
    <ToolbarActions>
      <ToolbarLink @route="vault.cluster.secrets.backend.edit-metadata" @model={{this.id}}>
        Edit metadata
      </ToolbarLink>
    </ToolbarActions>
  {{/if}}
</Toolbar>

<div class="form-section">
  <label class="title is-5 has-top-padding-m">
    Custom metadata
  </label>
</div>
<div class="box is-fullwidth is-sideless is-paddingless is-marginless">
  {{#each-in this.model.customMetadata as |key value|}}
    <InfoTableRow @alwaysRender={{false}} @label={{key}} @value={{value}} />
  {{else if this.noReadAccess}}
    <EmptyState
      @title="You do not have access to read secret metadata"
      @bottomBorder={{true}}
      @message="In order to edit secret metadata access, the UI requires read permissions; otherwise, data may be deleted. Edits can still be made via the API and CLI."
    />
  {{else}}
    <EmptyState
      @title="No custom metadata"
      @bottomBorder={{true}}
      @message="This data is version-agnostic and is usually used to describe the secret being stored."
    >
      {{#if this.model.canUpdateMetadata}}
        <LinkTo @route="vault.cluster.secrets.backend.edit-metadata" @model={{this.model.id}} data-test-add-custom-metadata>
          Add metadata
        </LinkTo>
      {{/if}}
    </EmptyState>
  {{/each-in}}
</div>
{{#unless this.noReadAccess}}
  <div class="form-section">
    <label class="title is-5 has-top-padding-m">
      Secret Metadata
    </label>
  </div>
  <div class="box is-fullwidth is-sideless is-paddingless is-marginless">
    <InfoTableRow @alwaysRender={{true}} @label="Maximum versions" @value={{this.model.maxVersions}} />
    <InfoTableRow @alwaysRender={{true}} @label="Check-and-Set required" @value={{this.model.casRequired}} />
    <InfoTableRow
      @alwaysRender={{true}}
      @label="Delete version after"
      @value={{if (eq this.model.deleteVersionAfter "0s") "Never delete" this.model.deleteVersionAfter}}
    />
  </div>
{{/unless}}