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

<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="confirm-header">
              Confirm delete
            </BlockSlot>
            <BlockSlot @name="confirm-body">
              <p>
                Are you sure you want to delete this namespace?
              </p>
            </BlockSlot>
            <BlockSlot @name="confirm-footer" as |Params|>
              <Params.button
                @text="Delete"
                {{on "click" Params.confirmAction}}
              />
            </BlockSlot>
          </Action>
        {{/if}}
      </Actions>
    {{/if}}
  </BlockSlot>
</ListCollection>