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

<PageHeader as |p|>
  <p.top>
    <Hds::Breadcrumb>
      <Hds::Breadcrumb::Item @text="Methods" @route="vault.cluster.access.mfa.methods.index" />
      <Hds::Breadcrumb::Item @text={{this.model.method.name}} @current={{true}} />
    </Hds::Breadcrumb>
  </p.top>
  <p.levelLeft>
    <h1 class="title is-3">
      <Icon @size="24" @name={{this.model.method.icon}} />
      {{this.model.method.name}}
    </h1>
  </p.levelLeft>
</PageHeader>

<div class="tabs-container box is-sideless is-fullwidth is-paddingless is-marginless">
  <nav class="tabs" aria-label="tabs">
    <ul>
      <LinkTo
        @route="vault.cluster.access.mfa.methods.method"
        @model={{this.model.method.id}}
        @query={{hash tab="config"}}
        data-test-tab="config"
      >
        Configuration
      </LinkTo>
      <LinkTo
        @route="vault.cluster.access.mfa.methods.method"
        @model={{this.model.method.id}}
        @query={{hash tab="enforcements"}}
        data-test-tab="enforcements"
      >
        Enforcements
      </LinkTo>
    </ul>
  </nav>
</div>

{{#if (eq this.tab "config")}}
  <Toolbar>
    <ToolbarActions>
      <ConfirmAction
        data-test-delete-mfa-config
        class="toolbar-button"
        @disabledMessage={{unless
          (is-empty this.model.enforcements)
          "This method cannot be deleted until its enforcements are deleted. This can be done from the 'Enforcements' tab."
        }}
        @buttonColor="secondary"
        @onConfirmAction={{this.deleteMethod}}
        @confirmMessage="Deleting this MFA configuration is permanent, and it will no longer be available."
        @buttonText="Delete"
      />
      <ToolbarLink
        @route="vault.cluster.access.mfa.methods.method.edit"
        @model={{this.model.method.id}}
        data-test-mfa-method-edit
      >
        Edit
      </ToolbarLink>
    </ToolbarActions>
  </Toolbar>
  <div class="box is-fullwidth is-sideless is-paddingless is-marginless">
    <InfoTableRow @label="ID" @value={{this.model.method.id}} @addCopyButton={{true}} />
    {{#each this.model.method.attrs as |attr|}}
      {{#if (eq attr.type "object")}}
        <InfoTableRow
          @alwaysRender={{not (is-empty-value (get this.model.method attr.name))}}
          @label={{or attr.options.label (to-label attr.name)}}
          @value={{stringify (get this.model.method attr.name)}}
        />
      {{else}}
        <InfoTableRow
          @alwaysRender={{not (is-empty-value (get this.model.method attr.name))}}
          @label={{or attr.options.label (to-label attr.name)}}
          @value={{get this.model.method attr.name}}
          @formatTtl={{eq attr.options.editType "ttl"}}
          @helperText={{attr.options.helperText}}
        />
      {{/if}}
    {{/each}}
  </div>
{{else if (eq this.tab "enforcements")}}
  <Toolbar>
    <ToolbarActions>
      <ToolbarLink @route="vault.cluster.access.mfa.enforcements.create" @type="add" data-test-enforcement-create>
        New enforcement
      </ToolbarLink>
    </ToolbarActions>
  </Toolbar>
  <div class="box is-fullwidth is-sideless is-paddingless is-marginless">
    {{#if (is-empty this.model.enforcements)}}
      <EmptyState
        @title="No enforcements found."
        @message="No enforcements are applied to this MFA method. Edit an existing enforcement or add a new one to get started."
      />
    {{else}}
      {{#each this.model.enforcements as |item|}}
        <Mfa::LoginEnforcementListItem @model={{item}} />
      {{/each}}
    {{/if}}
  </div>
{{/if}}