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

<BasicDropdown
  @horizontalPosition="right"
  @verticalPosition="below"
  @renderInPlace={{true}}
  class="sidebar-user-menu"
  data-test-user-menu
  as |Dropdown|
>
  <Dropdown.Trigger data-test-button="user-menu-trigger">
    <Hds::Button @isIconOnly={{true}} @size="large" @icon="user" @text="User menu" />
  </Dropdown.Trigger>
  <Dropdown.Content>
    <div class="popup-menu-content" data-test-user-menu-content>
      <div class="box">
        <div class="menu-label overflow-wrap">
          {{capitalize this.auth.authData.displayName}}
        </div>
        <nav class="menu">
          <ul class="menu-list">
            {{#if this.auth.allowExpiration}}
              <li class="token-alert is-flex" data-test-user-menu-item="token alert">
                <span><Icon @name="alert-triangle-fill" class="has-text-highlight" /></span>
                <span class="is-size-8 has-text-semibold">
                  We've stopped auto-renewing your token due to inactivity. It will expire on
                  {{date-format this.auth.tokenExpirationDate "MMMM do yyyy, h:mm:ss a"}}.
                </span>
              </li>
            {{/if}}
            {{#if this.hasEntityId}}
              <li>
                <LinkTo @route="vault.cluster.mfa-setup" data-test-user-menu-item="mfa">
                  Multi-factor authentication
                </LinkTo>
              </li>
            {{/if}}
            {{#if this.isUserpass}}
              <li>
                <LinkTo @route="vault.cluster.access.reset-password" data-test-user-menu-item="reset-password">
                  Reset password
                </LinkTo>
              </li>
            {{/if}}
            <li id="container">
              {{! container is required in navbar collapsed state }}
              <Hds::Copy::Button
                @text="Copy token"
                @textToCopy={{this.auth.currentToken}}
                @isFullWidth={{true}}
                @container="#container"
                class="in-dropdown link is-flex-start"
                @onSuccess={{(fn (set-flash-message "Token copied!"))}}
                @onError={{(fn
                  (set-flash-message "Clipboard copy failed. The Clipboard API requires a secure context." "danger")
                )}}
                data-test-copy-button
              />
            </li>
            {{#if (is-before (now interval=1000) this.auth.tokenExpirationDate)}}
              {{#if this.auth.authData.renewable}}
                <li>
                  {{! TODO Hds::Button replacement skipped in favor of updating it when there is a Hds::Dropdown swapout }}
                  <button
                    type="button"
                    {{on "click" this.renewToken}}
                    class="link button {{if this.isRenewing 'is-loading'}}"
                    data-test-user-menu-item="renew token"
                  >
                    Renew token
                  </button>
                </li>
              {{/if}}
              <ConfirmAction
                @isInDropdown={{true}}
                @confirmTitle="Revoke {{get this.auth 'authData.displayName'}}?"
                @onConfirmAction={{action "revokeToken"}}
                @buttonText="Revoke token"
                @confirmMessage="You will not be able to log in again with this token."
                data-test-user-menu-item="revoke token"
              />
            {{/if}}
            <li>
              <LinkTo @route="vault.cluster.logout" @model={{this.currentCluster.cluster.name}} id="logout">
                Log out
              </LinkTo>
            </li>
          </ul>
        </nav>
      </div>
    </div>
  </Dropdown.Content>
</BasicDropdown>