{{!
  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="confirmation" as |Confirmation|>
            <Confirmation class="warning">
              <BlockSlot @name="header">
                Confirm delete
              </BlockSlot>
              <BlockSlot @name="body">
                <p>
                  Are you sure you want to delete this role?
                </p>
              </BlockSlot>
              <BlockSlot @name="confirm" as |Confirm|>
                <Confirm>Delete</Confirm>
              </BlockSlot>
            </Confirmation>
          </BlockSlot>
        </Action>
{{/if}}
      </Actions>
    </BlockSlot>
</ListCollection>