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

<PageHeader as |p|>
  <p.top>
    <Hds::Breadcrumb>
      <Hds::Breadcrumb::Item
        @text={{pluralize this.itemType}}
        @route="vault.cluster.access.method.item.list"
        @models={{array this.mountPath this.itemType}}
      />
      <Hds::Breadcrumb::Item @text={{if (eq this.mode "show") this.model.id (capitalize this.mode)}} @current={{true}} />
    </Hds::Breadcrumb>
  </p.top>
  <p.levelLeft>
    {{#if (eq this.mode "show")}}
      <h1 class="title is-3">
        {{this.model.id}}
      </h1>
    {{else}}
      <h1 class="title is-3">
        {{capitalize this.mode}}
        {{singularize this.itemType}}
        {{#if (eq this.mode "edit")}}
          {{this.model.id}}
        {{/if}}
      </h1>
    {{/if}}
  </p.levelLeft>
</PageHeader>
{{#if (eq this.mode "show")}}
  <Toolbar>
    <ToolbarActions>
      <ConfirmAction
        @buttonText="Delete {{this.itemType}}"
        class="toolbar-button"
        @buttonColor="secondary"
        @onConfirmAction={{action "deleteItem"}}
        @confirmMessage="Are you sure you want to delete {{this.itemType}} {{this.model.id}}?"
      />
      <div class="toolbar-separator"></div>
      <ToolbarLink
        @route="vault.cluster.access.method.item.edit"
        @models={{array this.mountPath this.itemType this.model.id}}
        data-test-configure-link="true"
      >
        Edit
        {{singularize this.itemType}}
      </ToolbarLink>
    </ToolbarActions>
  </Toolbar>
{{/if}}
{{#if (eq this.mode "show")}}
  <FieldGroupShow @model={{this.model}} @showAllFields={{true}} />
{{else}}
  <form {{action (perform this.saveModel) on="submit"}}>
    <div class="box is-sideless is-fullwidth is-marginless">
      <NamespaceReminder @mode="save" @noun={{this.itemType}} />
      <MessageError @model={{this.model}} />
      <FormFieldGroups @model={{this.model}} @mode={{this.mode}} @modelValidations={{this.modelValidations}} />
    </div>
    <div class="field is-grouped-split box is-fullwidth is-bottomless">
      <Hds::ButtonSet>
        <Hds::Button
          @text="Save"
          @icon={{if this.saveModel.isRunning "loading"}}
          type="submit"
          disabled={{this.saveModel.isRunning}}
          data-test-submit
        />
        {{#if (eq this.mode "create")}}
          <Hds::Button
            @text="Cancel"
            @color="secondary"
            @route="vault.cluster.access.method.item.list"
            @models={{array this.mountPath this.itemType}}
            data-test-cancel-link={{true}}
          />
        {{else}}
          <Hds::Button
            @text="Cancel"
            @color="secondary"
            @route="vault.cluster.access.method.item.show"
            @models={{array this.mountPath this.itemType this.model.id}}
            data-test-cancel-link={{true}}
          />
        {{/if}}
      </Hds::ButtonSet>
    </div>
  </form>
{{/if}}