@namespace BootstrapBlazor.Components
@inherits PopoverCompleteBase<string>

@if (IsShowLabel)
{
    <BootstrapLabel required="@Required" for="@InputId" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText"/>
}
<div class="@ClassString" id="@Id">
    <input @attributes="AdditionalAttributes" id="@InputId" class="@ClassName" autocomplete="off" type="text"
           data-bs-toggle="@ToggleString" data-bs-placement="@PlacementString"
           data-bs-offset="@OffsetString" data-bs-custom-class="@CustomClassString"
           data-bb-auto-dropdown-focus="@ShowDropdownListOnFocusString" data-bb-debounce="@DurationString"
           data-bb-skip-esc="@SkipEscString" data-bb-skip-enter="@SkipEnterString" data-bb-blur="@TriggerBlurString"
           data-bb-scroll-behavior="@ScrollIntoViewBehaviorString" data-bb-trigger-delete="true"
           placeholder="@PlaceHolder" disabled="@Disabled" />
    <span class="form-select-append"><i class="@Icon"></i></span>
    <span class="form-select-append ac-loading"><i class="@LoadingIcon"></i></span>
    @if (GetClearable())
    {
        <span class="@ClearClassString"><i class="@ClearIcon"></i></span>
    }
    <RenderTemplate @ref="_dropdown">
        @RenderDropdown
    </RenderTemplate>
</div>

@code {
    RenderFragment RenderDropdown =>
    @<div class="dropdown-menu">
        <div class="dropdown-menu-body">
            @foreach (var item in Rows)
            {
                <div @key="item" class="dropdown-item" @onclick="() => OnClickItem(item)">
                    @if (ItemTemplate == null)
                    {
                        <div>@item</div>
                    }
                    else
                    {
                        @ItemTemplate(item)
                    }
                </div>
            }
            @if (ShowNoDataTip && Rows.Count == 0)
            {
                <div class="dropdown-item">@NoDataTip</div>
            }
        </div>
    </div>;
}
