{{title 'Namespaces'}}
{{#let (selectable-key-values
    (array "Name:asc" "A to Z")
    (array "Name:desc" "Z to A")
      selected=sortBy
  )
  as |sort|
}}
<EventSource @src={{items}} />
<AppView @class="nspace list" @loading={{isLoading}}>
  <BlockSlot @name="notification" as |status type subject|>
    {{partial 'dc/nspaces/notifications'}}
  </BlockSlot>
  <BlockSlot @name="header">
    <h1>
      Namespaces
    </h1>
  </BlockSlot>
  <BlockSlot @name="actions">
      <a data-test-create href="{{href-to 'dc.nspaces.create'}}" class="type-create">Create</a>
  </BlockSlot>
  <BlockSlot @name="toolbar">
  {{#if (gt items.length 0)}}
    <SearchBar
      @value={{search}}
      @onsearch={{action (mut search) value="target.value"}}
      @secondary="sort"
      @selected={{sort.selected}}
      @options={{sort.items}}
      @onchange={{action (mut sortBy) value='target.selected.key'}}
    />
  {{/if}}
  </BlockSlot>
  <BlockSlot @name="content">
  {{#let (sort-by (comparator 'nspace' sort.selected.key) items) as |sorted|}}
    <ChangeableSet @dispatcher={{searchable 'nspace' sorted}} @terms={{search}}>
      <BlockSlot @name="set" as |filtered|>
        <ConsulNspaceList
          @items={{filtered}}
          @ondelete={{queue (action send 'delete')}}
        >
          <EmptyState @allowLogin={{true}}>
            <BlockSlot @name="header">
              <h2>
                {{#if (gt items.length 0)}}
                  No namespaces found
                {{else}}
                  Welcome to Namespaces
                {{/if}}
              </h2>
            </BlockSlot>
            <BlockSlot @name="body">
              <p>
                {{#if (gt items.length 0)}}
                  No namespaces where found matching that search, or you may not have access to view the namespaces you are searching for.
                {{else}}
                  There don't seem to be any namespaces, or you may not have access to view namespaces yet.
                {{/if}}
              </p>
            </BlockSlot>
            <BlockSlot @name="actions">
              <li class="docs-link">
                <a href="{{env 'CONSUL_DOCS_URL'}}/commands/namespace" rel="noopener noreferrer" target="_blank">Documentation on namespaces</a>
              </li>
              <li class="learn-link">
                <a href="{{env 'CONSUL_DOCS_LEARN_URL'}}/consul/namespaces/secure-namespaces" rel="noopener noreferrer" target="_blank">Read the guide</a>
              </li>
            </BlockSlot>
          </EmptyState>
        </ConsulNspaceList>
      </BlockSlot>
    </ChangeableSet>
  {{/let}}
  </BlockSlot>
</AppView>
{{/let}}