{{!
  Copyright IBM Corp. 2016, 2025
  SPDX-License-Identifier: BUSL-1.1
}}

<Page::Header
  @title="Edit Secret Metadata"
  @description="The options below are all version-agnostic; they apply to all versions of this secret."
  @icon={{@backend.icon}}
>
  <:breadcrumbs>
    <Page::Breadcrumbs @breadcrumbs={{@breadcrumbs}} />
  </:breadcrumbs>
</Page::Header>

{{#if @capabilities.canUpdateMetadata}}
  <form {{on "submit" (perform this.save)}}>
    <div class="box is-fullwidth is-marginless">
      <NamespaceReminder @mode="update" @noun="KV secret metadata" />
      <MessageError @errorMessage={{this.errorBanner}} class="has-top-margin-s" />
      <KvMetadataFields @form={{@form}} @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" @onCancel}}
          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}}
  <Hds::ApplicationState class="top-padding-32 is-marginless" as |A|>
    <A.Header @title="You do not have permissions to edit metadata" @titleTag="h2" data-test-empty-state-title />
    <A.Body @text="Ask your administrator if you think you should have access." data-test-empty-state-message />
    <A.Footer data-test-empty-state-actions as |F|>
      <F.LinkStandalone @icon="chevron-left" @text="Go back" @route="secret.metadata.index" />
      <F.LinkStandalone
        @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}}
      />
    </A.Footer>
  </Hds::ApplicationState>
{{/if}}