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

<ListCollection
  class="consul-nspace-list"
  ...attributes
  @items={{@items}}
  @linkable="linkable nspace"
as |item|>
    <BlockSlot @name="header">
{{#if item.DeletedAt}}
    <p>
      Deleting {{item.Name}}...
    </p>
{{else}}
      <a data-test-nspace={{item.Name}} href={{href-to 'dc.nspaces.edit' item.Name}}>{{item.Name}}</a>
{{/if}}
    </BlockSlot>
    <BlockSlot @name="details">
{{#if item.Description}}
      <dl>
        <dt>Description</dt>
        <dd data-test-description>
          {{item.Description}}
        </dd>
      </dl>
{{/if}}
  {{#if (env 'CONSUL_ACLS_ENABLED')}}
      <Consul::Token::Ruleset::List @item={{item}} />
  {{/if}}
    </BlockSlot>
    <BlockSlot @name="actions" as |Actions|>
{{#if (not item.DeletedAt)}}
      <Actions as |Action|>
        <Action data-test-edit-action @href={{href-to 'dc.nspaces.edit' item.Name}}>
          <BlockSlot @name="label">
{{#if (can "write nspace" item=item)}}
            Edit
{{else}}
            View
{{/if}}
          </BlockSlot>
        </Action>
      {{#if (can "delete nspace" 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 namespace?
                </p>
              </BlockSlot>
              <BlockSlot @name="confirm" as |Confirm|>
                <Confirm>Delete</Confirm>
              </BlockSlot>
            </Confirmation>
          </BlockSlot>
        </Action>
      {{/if}}
      </Actions>
{{/if}}
    </BlockSlot>
</ListCollection>