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

<PageHeader as |p|>
  <p.levelLeft>
    <h1 class="title is-3 title-with-icon" data-test-page-title>
      {{#if this.showEnable}}
        {{#let (find-by "type" this.mountForm.type @mountTypes) as |typeInfo|}}
          {{#if typeInfo.glyph}}
            <Icon @name={{typeInfo.glyph}} @size="24" class="has-text-grey-light" />
          {{/if}}
          {{#if (eq @mountCategory "secret")}}
            {{concat "Enable " (or typeInfo.displayName this.mountForm.type) " Secrets Engine"}}
          {{else}}
            {{concat "Enable " (or typeInfo.displayName this.mountForm.type) " Authentication Method"}}
          {{/if}}
        {{/let}}
      {{else if (eq @mountCategory "secret")}}
        Enable a Secrets Engine
      {{else}}
        Enable an Authentication Method
      {{/if}}
    </h1>
  </p.levelLeft>
</PageHeader>

<div class="box is-sideless is-bottomless is-fullwidth is-marginless">
  <NamespaceReminder @mode="enable" @noun={{if (eq @mountCategory "secret") "Secret Engine" "Auth Method"}} />
  <MessageError @errorMessage={{this.errorMessage}} />
  {{#if this.mountForm.type}}
    <form {{on "submit" (perform this.mountBackend)}}>
      <FormFieldGroups
        @model={{this.mountForm}}
        @groupName="formFieldGroups"
        @renderGroup="default"
        @modelValidations={{this.modelValidations}}
        @onKeyUp={{this.onKeyUp}}
      />

      <FormFieldGroups @model={{this.mountForm}} @renderGroup="Method Options" @groupName="formFieldGroups">
        <:identityTokenKey>
          <SearchSelectWithModal
            @id="key"
            @fallbackComponent="input-search"
            @inputValue={{this.mountForm.data.config.identity_token_key}}
            @onChange={{this.handleIdentityTokenKeyChange}}
            @models={{array "oidc/key"}}
            @selectLimit="1"
            @modalFormTemplate="modal-form/oidc-key-template"
            @placeholder="Search for an existing OIDC key, or type a new key name to create it."
            @fallbackComponentPlaceholder="Input a key name"
            @modalSubtext="This key will be created in the OIDC key path."
          />
        </:identityTokenKey>
      </FormFieldGroups>

      <div class="field is-grouped box is-fullwidth is-bottomless">
        <div class="control">
          <Hds::Button
            @text={{if (eq @mountCategory "secret") "Enable engine" "Enable method"}}
            @icon={{if this.mountBackend.isRunning "loading"}}
            type="submit"
            data-test-submit
            disabled={{this.mountBackend.isRunning}}
          />
        </div>
        <div class="control">
          <Hds::Button @text="Back" @color="secondary" data-test-back-button {{on "click" (fn this.setMountType "")}} />
        </div>
        {{#if this.invalidFormAlert}}
          <div class="control">
            <AlertInline @type="danger" class="has-top-padding-s" @message={{this.invalidFormAlert}} />
          </div>
        {{/if}}
      </div>
    </form>
  {{else}}
    {{!  Type not yet set, show type options }}
    <MountBackend::TypeForm
      @setMountType={{this.setMountType}}
      @mountCategory={{@mountCategory}}
      @pluginCatalogData={{@mountModel.pluginCatalogData}}
      @pluginCatalogError={{@mountModel.pluginCatalogError}}
    />
  {{/if}}
</div>