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

<ListCollection
  class="consul-role-list"
  ...attributes
  @items={{@items}}
as |item|>
    <BlockSlot @name="header">
      <a data-test-role={{item.Name}} href={{href-to 'dc.acls.roles.edit' item.ID}}>{{item.Name}}</a>
    </BlockSlot>
    <BlockSlot @name="details">
      <Consul::Token::Ruleset::List @item={{item}} />
      <dl>
        <dt>Description</dt>
        <dd data-test-description>
            {{item.Description}}
        </dd>
      </dl>
    </BlockSlot>
    <BlockSlot @name="actions" as |Actions|>
      <Actions as |Action|>
        <Action data-test-edit-action @href={{href-to 'dc.acls.roles.edit' item.ID}}>
          <BlockSlot @name="label">
{{#if (can "write role" item=item)}}
            Edit
{{else}}
            View
{{/if}}
          </BlockSlot>
        </Action>
{{#if (can "delete role" item=item)}}
        <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 role?
            </p>
          </BlockSlot>
          <BlockSlot @name='confirm-footer' as |Params|>
            <Params.button @text='Delete' {{on 'click' Params.confirmAction}} />
          </BlockSlot>
        </Action>
{{/if}}
      </Actions>
    </BlockSlot>
</ListCollection>