{{!
  Copyright (c) HashiCorp, Inc.
  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 @model.isNew}}
    {{#each @model.formFields as |attr|}}
      <FormField @attr={{attr}} @model={{@model}} @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-configure-save-button
      />
      <Hds::Button
        @text="Cancel"
        @color="secondary"
        disabled={{this.save.isRunning}}
        {{on "click" this.onCancel}}
        data-test-cancel-button
      />
    </Hds::ButtonSet>
    {{#if this.invalidFormAlert}}
      <AlertInline
        data-test-invalid-form-alert
        class="has-top-padding-s"
        @type="danger"
        @message={{this.invalidFormAlert}}
      />
    {{/if}}
  {{else}}
    {{! Model 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={{@model.publicKey}}
          @displayOnly={{true}}
          @allowCopy={{true}}
          data-test-input="public-key"
        />
      </div>
    </div>
    <Hds::ButtonSet>
      <Hds::Copy::Button
        @text="Copy"
        @textToCopy={{@model.publicKey}}
        @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-delete-public-key
      />
    </Hds::ButtonSet>
  {{/if}}
</form>