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

<form {{on "submit" (perform this.save)}} aria-label="save ssh creds" class="has-top-padding-m" data-test-configure-form>
  <NamespaceReminder @mode="save" @noun="configuration" />
  <MessageError @errorMessage={{this.errorMessage}} />
  {{#if @configForm.isNew}}
    {{#each @configForm.formFields as |attr|}}
      <FormField @attr={{attr}} @model={{@configForm}} @modelValidations={{this.modelValidations}} />
    {{/each}}
    <hr class="has-background-gray-300" />
    <Hds::ButtonSet>
      <Hds::Button
        @text="Save"
        @icon={{if this.save.isRunning "loading"}}
        type="submit"
        disabled={{this.save.isRunning}}
        data-test-submit
      />
      <Hds::Button
        @text="Cancel"
        @color="secondary"
        disabled={{this.save.isRunning}}
        {{on "click" this.onCancel}}
        data-test-cancel
      />
    </Hds::ButtonSet>
    {{#if this.invalidFormAlert}}
      <AlertInline
        data-test-invalid-form-alert
        class="has-top-padding-s"
        @type="danger"
        @message={{this.invalidFormAlert}}
      />
    {{/if}}
  {{else}}
    {{! Form is not new and keys have already been created. Require user deletes the keys before creating new ones }}
    <p class="has-text-grey-dark has-top-bottom-margin">
      NOTE: You must delete your existing certificate and key before saving new values.
    </p>

    <div class="box is-fullwidth is-sideless" data-test-edit-config-section>
      <label for="publicKey" class="is-label">
        Public key
      </label>
      <div class="control">
        <MaskedInput
          @name="publicKey"
          @id="publicKey"
          @value={{@configForm.public_key}}
          @displayOnly={{true}}
          @allowCopy={{true}}
          data-test-input="public-key"
        />
      </div>
    </div>
    <Hds::ButtonSet>
      <Hds::Copy::Button
        @text="Copy"
        @textToCopy={{@configForm.public_key}}
        @onError={{fn (set-flash-message "Clipboard copy failed. The Clipboard API requires a secure context." "danger")}}
        class="primary"
      />
      <ConfirmAction
        @buttonText="Delete"
        @buttonColor="secondary"
        @confirmMessage="Confirming will remove the CA certificate information."
        @onConfirmAction={{this.deleteCaConfig}}
        data-test-button="delete-public-key"
      />
    </Hds::ButtonSet>
  {{/if}}
</form>