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

<KvPageHeader @breadcrumbs={{@breadcrumbs}} @pageTitle="Patch Secret to New Version" />
{{#if this.controlGroupError}}
  <ControlGroupInlineError @error={{this.controlGroupError}} class="has-top-margin-s has-bottom-margin-s">
    <:customMessage>
      <strong>
        You can re-submit the form once access is granted. Ask your authorizer when to attempt saving again.
      </strong>
    </:customMessage>
  </ControlGroupInlineError>
{{/if}}
<MessageError @errorMessage={{this.errorMessage}} />

<div class="box is-sideless is-fullwidth is-bottomless">
  <NamespaceReminder @mode="patch" @noun="secret" />
  <Hds::Form::TextInput::Field name="secret path" @value={{@path}} disabled data-test-field="Path" as |F|>
    <F.Label>Path for this secret</F.Label>
  </Hds::Form::TextInput::Field>

  <hr class="has-background-gray-200" />

  <Hds::Text::Display @tag="h2" @size="300" class="has-bottom-padding-s">Patch secret data</Hds::Text::Display>
  <Hds::Alert @type="compact" @icon="alert-triangle-fill" @color="warning" class="has-bottom-padding-m" as |A|>
    <A.Description>
      The
      <code>PATCH</code>
      action allows you to partially update or add a key-value pair to the current version of the secret. The values will
      remain the same in the new version if no changes are made to them.
    </A.Description>
  </Hds::Alert>

  <Hds::Form::Radio::Group @name="patch-method" class="has-bottom-margin-m" as |G|>
    <G.Legend>Edit via</G.Legend>
    <G.HelperText>
      Choose how to patch the secret data.
      <strong>Switching to another method will reset the form data.</strong>
    </G.HelperText>

    {{#each (array "JSON" "UI") as |method|}}
      <G.RadioField
        @value={{method}}
        {{on "change" this.selectPatchMethod}}
        checked={{eq this.patchMethod method}}
        data-test-input={{method}}
        as |F|
      >
        <F.Label>{{method}}</F.Label>
      </G.RadioField>
    {{/each}}
  </Hds::Form::Radio::Group>

  {{#if (eq this.patchMethod "UI")}}
    <KvPatch::Editor::Form
      @isSaving={{this.save.isRunning}}
      @onCancel={{this.onCancel}}
      @onSubmit={{perform this.save}}
      @subkeys={{@subkeys}}
      @submitError={{this.invalidFormAlert}}
    />
  {{else}}
    <KvPatch::JsonForm
      @isSaving={{this.save.isRunning}}
      @onCancel={{this.onCancel}}
      @onSubmit={{perform this.save}}
      @subkeys={{@subkeys}}
      @submitError={{this.invalidFormAlert}}
    />
  {{/if}}
</div>