@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore

@inherits DbContextPage

<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.Center" Gap="0.5rem" class="rz-p-sm-12">
    <RadzenLabel Text="Select Value" Component="DropDownFiltering" />
    <RadzenDropDown @ref=@radzenDropDown @bind-SearchText=SearchText FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterOperator="StringFilterOperator.StartsWith" AllowFiltering="true"
                    Data=@customers TextProperty="@nameof(Customer.CompanyName)" ValueProperty="@nameof(Customer.CustomerID)" AllowClear="true" @bind-Value=value Style="width: 100%; max-width: 400px;" Name="DropDownFiltering" />
</RadzenStack>

<div class="rz-p-sm-3 rz-text-align-start"> 
    <RadzenLabel Text="@searchTextStatus" />
</div>

@code {
    RadzenDropDown<string> radzenDropDown;
    IEnumerable<Customer> customers;
    string value;
    string searchTextStatus;

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        customers = dbContext.Customers;

        searchTextStatus = $"Search text: {searchText}";
    }

    string searchText = "al";

    public string SearchText
    {
        get
        {
            return searchText;
        }
        set
        {
            if (searchText != value)
            {
                searchText = value;
                searchTextStatus = $"Search text: {searchText}";
                Console.WriteLine($"Search text: {radzenDropDown.SearchText}");
            }
        }
    }
}
