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

<div
  class="child-selector {{this.type}}-child-selector"
  {{fix-super-select-aria}}
  ...attributes
>
{{yield}}
{{#if (not @disabled)}}
  <YieldSlot @name="create">{{yield}}</YieldSlot>
  <label class="type-text">
    <span><YieldSlot @name="label">{{yield}}</YieldSlot></span>
    {{!-- {{#if isOpen}} --}}
      <DataSource
        @src={{uri '/${partition}/${nspace}/${dc}/${type}'
          (hash
            partition=@partition
            nspace=@nspace
            dc=@dc
            type=(pluralize this.type)
          )
        }}
        @onchange={{action (mut this.allOptions) value="data"}}
      />
    {{!-- {{/if}} --}}
    <DataCollection
      @type={{this.type}}
      @sort='Name:asc'
      @filters={{hash
        searchproperties=(array 'Name')
      }}
      @items={{this.options}}
    as |collection|>
      <Hds::Form::SuperSelect::Single::Field
        @searchEnabled={{true}}
        @onFilter={{action collection.search}}
        @options={{sort-by 'Name:asc' this.options}}
        @placeholder={{@placeholder}}
        @onChange={{action "change" "items[]" @items}}
        @label="Select {{this.type}}"
        @isOptional={{true}}
        @searchField="Name"
      as |F|>
        <F.Options>{{F.options.Name}}</F.Options>
      </Hds::Form::SuperSelect::Single::Field>
    </DataCollection>
  </label>
{{/if}}
{{#if (gt @items.length 0)}}
  <YieldSlot @name="set" @params={{block-params (action "remove")}}>{{yield}}</YieldSlot>
{{else}}

{{/if}}
</div>