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

<KvPageHeader @breadcrumbs={{@breadcrumbs}} @pageTitle="Create New Version">
  <:toolbarFilters>
    <Toggle @name="json" @checked={{this.showJsonView}} @onChange={{fn (mut this.showJsonView)}}>
      <span class="has-text-grey">JSON</span>
    </Toggle>
  </:toolbarFilters>
</KvPageHeader>

{{#if this.showOldVersionAlert}}
  <Hds::Alert data-test-secret-version-alert @type="inline" @color="warning" class="has-top-bottom-margin" as |A|>
    <A.Title>Warning</A.Title>
    <A.Description>
      You are creating a new version based on data from Version
      {{@secret.version}}. The current version for
      <code>{{@path}}</code>
      is Version
      {{@metadata.current_version}}.
    </A.Description>
  </Hds::Alert>
{{/if}}

{{#if (eq @secret.failReadErrorCode 403)}}
  <Hds::Alert data-test-secret-no-read-alert @type="inline" @color="warning" class="has-top-bottom-margin" as |A|>
    <A.Title>Warning</A.Title>
    <A.Description>
      You do not have read permissions for this secret data. Saving will overwrite the existing secret.
    </A.Description>
  </Hds::Alert>
{{/if}}

<KvCreateEditForm
  @form={{@form}}
  @path={{@path}}
  @backend={{@backend}}
  @showJson={{this.showJsonView}}
  @onChange={{this.onSecretDataUpdate}}
>
  <div class="has-top-margin-m">
    <Toggle @name="Show diff" @onChange={{fn (mut this.showDiff)}} @checked={{this.showDiff}}>
      <span class="ttl-picker-label is-large">Show diff</span><br />
      <div class="description has-text-grey" data-test-diff-description>{{if
          this.diffDelta
          "Showing the diff will reveal secret values"
          "No changes to show. Update secret to view diff"
        }}</div>
      {{#if this.showDiff}}
        <div class="form-section visual-diff text-grey-lightest background-color-black has-top-margin-s">
          <pre data-test-visual-diff>{{sanitized-html this.visualDiff}}</pre>
        </div>
      {{/if}}
    </Toggle>
  </div>
</KvCreateEditForm>