<Route
  @name={{routeName}}
  @title="Nodes"
as |route|>
  <EventSource @src={{items}} />
  <EventSource @src={{leader}} />
  {{#let

    (hash
      value=(or sortBy "Status:asc")
      change=(action (mut sortBy) value="target.selected")
    )

    (hash
      status=(hash
        value=(if status (split status ',') undefined)
        change=(action (mut status) value="target.selectedItems")
      )
      searchproperty=(hash
        value=(if (not-eq searchproperty undefined)
          (split searchproperty ',')
          searchProperties
        )
        change=(action (mut searchproperty) value="target.selectedItems")
        default=searchProperties
      )
    )

    items

  as |sort filters items|}}
    <AppView>
      <BlockSlot @name="header">
        <h1>
          Nodes <em>{{format-number items.length}} total</em>
        </h1>
        <label for="toolbar-toggle"></label>
      </BlockSlot>
      <BlockSlot @name="toolbar">
      {{#if (gt items.length 0) }}
          <Consul::Node::SearchBar
            @search={{search}}
            @onsearch={{action (mut search) value="target.value"}}

            @sort={{sort}}

            @filter={{filters}}
          />
      {{/if}}
      </BlockSlot>
      <BlockSlot @name="content">
        <DataCollection
          @type="node"
          @sort={{sort.value}}
          @filters={{filters}}
          @search={{search}}
          @items={{items}}
        as |collection|>
          <collection.Collection>
            <Consul::Node::List
              @items={{collection.items}}
              @leader={{leader}}
            />
          </collection.Collection>
          <collection.Empty>
            <EmptyState>
              <BlockSlot @name="body">
                <p>
                  There don't seem to be any registered nodes, or you may not have access to view nodes yet.
                </p>
              </BlockSlot>
            </EmptyState>
          </collection.Empty>
        </DataCollection>
      </BlockSlot>
    </AppView>
  {{/let}}
  </Route>