{{!
  Copyright (c) HashiCorp, Inc.
  SPDX-License-Identifier: BUSL-1.1
}}

<ListCollection class='consul-token-list' @items={{@items}} as |item|>
  <BlockSlot @name='header'>
    {{#if (eq item.AccessorID @token.AccessorID)}}
      <dl rel='me'>
        <dt></dt>
        <dd>
          <Tooltip @position='top-start'>
            Your token
          </Tooltip>
        </dd>
      </dl>
    {{/if}}
    <a
      data-test-token={{item.AccessorID}}
      href={{href-to 'dc.acls.tokens.edit' item.AccessorID}}
    >{{substr item.AccessorID -8}}</a>
  </BlockSlot>
  <BlockSlot @name='details'>
    <dl>
      <dt>Scope</dt>
      <dd>
        {{if item.Local 'local' 'global'}}
      </dd>
    </dl>
    <Consul::Token::Ruleset::List @item={{item}} />
    <dl>
      <dt>Description</dt>
      <dd data-test-description>
        {{or item.Description item.Name}}
      </dd>
    </dl>
  </BlockSlot>
  <BlockSlot @name='actions' as |Actions|>
    {{#if item.hasSecretID}}
      <ConsulCopyButton @value={{item.SecretID}} @name={{t 'components.consul.token.secretID'}}>
        {{t 'components.consul.token.secretID'}}
      </ConsulCopyButton>
    {{/if}}
    <Actions as |Action|>
      <Action data-test-edit-action @href={{href-to 'dc.acls.tokens.edit' item.AccessorID}}>
        <BlockSlot @name='label'>
          {{#if (can 'write token' item=item)}}
            Edit
          {{else}}
            View
          {{/if}}
        </BlockSlot>
      </Action>
      {{#if (can 'duplicate token' item=item)}}
        <Action data-test-clone-action @onclick={{action @onclone item}}>
          <BlockSlot @name='label'>
            Duplicate
          </BlockSlot>
        </Action>
      {{/if}}

      {{#if (eq item.AccessorID @token.AccessorID)}}
        <Action data-test-logout-action class='dangerous' @onclick={{action @onlogout item}}>
          <BlockSlot @name='label'>
            Logout
          </BlockSlot>
          <BlockSlot @name='confirm-header'>
            Confirm logout
          </BlockSlot>
          <BlockSlot @name='confirm-body'>
            <p>
              Are you sure you want to stop using this ACL token? This will log you out.
            </p>
          </BlockSlot>
          <BlockSlot @name='confirm-footer' as |Params|>
            <Params.button @text='Logout' {{on 'click' Params.confirmAction}} />
          </BlockSlot>
        </Action>
      {{else}}
        <Action data-test-use-action @onclick={{action @onuse item}}>
          <BlockSlot @name='label'>
            Use
          </BlockSlot>
          <BlockSlot @name='confirm-header'>
            Confirm use
          </BlockSlot>
          <BlockSlot @name='confirm-body'>
            <p>
              Are you sure you want to use this ACL token?
            </p>
          </BlockSlot>
          <BlockSlot @name='confirm-footer' as |Params|>
            <Params.button @text='Use' {{on 'click' Params.confirmAction}} />
          </BlockSlot>
        </Action>
      {{/if}}

      {{#if (can 'delete token' item=item token=@token)}}
        <Action data-test-delete-action @onclick={{action @ondelete item}} class='dangerous'>
          <BlockSlot @name='label'>
            Delete
          </BlockSlot>
          <BlockSlot @name='confirm-header'>
            Confirm delete
          </BlockSlot>
          <BlockSlot @name='confirm-body'>
            <p>
              Are you sure you want to delete this token?
            </p>
          </BlockSlot>
          <BlockSlot @name='confirm-footer' as |Params|>
            <Params.button @text='Delete' {{on 'click' Params.confirmAction}} />
          </BlockSlot>
        </Action>
      {{/if}}

    </Actions>
  </BlockSlot>
</ListCollection>