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

<KvPageHeader @breadcrumbs={{@breadcrumbs}} @pageTitle="Edit Secret Metadata" />

{{#if @metadata.canUpdateMetadata}}
  <hr class="is-marginless has-background-gray-200" />
  <p class="has-top-margin-m has-bottom-margin-m">
    The options below are all version-agnostic; they apply to all versions of this secret.
  </p>
  <form {{on "submit" (perform this.save)}}>
    <div class="box is-sideless is-fullwidth is-marginless">
      <NamespaceReminder @mode="update" @noun="KV secret metadata" />
      <MessageError @errorMessage={{this.errorBanner}} class="has-top-margin-s" />
      <KvMetadataFields @metadata={{@metadata}} @modelValidations={{this.modelValidations}} />
    </div>
    <div class="field is-grouped is-grouped-split is-fullwidth box is-bottomless">
      <div class="has-top-padding-s">
        <Hds::Button
          @text="Update"
          @icon={{if this.save.isRunning "loading"}}
          type="submit"
          disabled={{this.save.isRunning}}
          data-test-kv-save
        />
        <Hds::Button
          @text="Cancel"
          @color="secondary"
          class="has-left-margin-s"
          disabled={{this.save.isRunning}}
          {{on "click" this.cancel}}
          data-test-kv-cancel
        />
        {{#if this.invalidFormAlert}}
          <div class="control">
            <AlertInline
              data-test-invalid-form-alert
              @type="danger"
              class="has-top-padding-s"
              @message={{this.invalidFormAlert}}
            />
          </div>
        {{/if}}
      </div>
    </div>
  </form>
{{else}}
  <EmptyState
    @title="You do not have permissions to edit metadata"
    @message="Ask your administrator if you think you should have access."
  >
    <Hds::Link::Standalone @icon="chevron-left" @text="Go back" @route="secret.metadata.index" />
    <Hds::Link::Standalone
      @icon="docs-link"
      @iconPosition="trailing"
      @text="KV v2 metadata API docs"
      @href={{doc-link "/vault/api-docs/secret/kv/kv-v2#create-update-metadata"}}
      @isHrefExternal={{true}}
    />
  </EmptyState>
{{/if}}