{{!
  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">
        <button
          type="submit"
          class="button is-primary {{if this.save.isRunning 'is-loading'}}"
          disabled={{this.save.isRunning}}
          data-test-kv-save
        >
          Update
        </button>
        <button
          type="button"
          class="button has-left-margin-s"
          disabled={{this.save.isRunning}}
          {{on "click" this.cancel}}
          data-test-kv-cancel
        >
          Cancel
        </button>
        {{#if this.invalidFormAlert}}
          <div class="control">
            <AlertInline
              data-test-invalid-form-alert
              @type="danger"
              @paddingTop={{true}}
              @message={{this.invalidFormAlert}}
              @mimicRefresh={{true}}
            />
          </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."
  >
    <LinkTo @route="secret.metadata.index">
      View Metadata
    </LinkTo>
    <DocLink @path="/vault/api-docs/secret/kv/kv-v2#create-update-metadata">More here</DocLink>
  </EmptyState>
{{/if}}