@implements IDisposable

@if (cities != null && cities.Count > 0)
{
  <div class="container-fluid text-center">
    <div class="row">
      @foreach(var city in cities)
      {
      <CityComponent
        city="@city"
        selectedCity="@this.selectedCity"
        SelectCityCallBack="HandleCitySelection">
      </CityComponent>
      }
    </div>
  </div>
}

@code {
  private List<string> cities = ServersRepository.GetCities();

  [Parameter]
  public EventCallback<string> SelectCityCallBack { get; set; }
  [Parameter]
  public string? selectedCity { get; set; } = "Eindhoven";

  public void ClearSelection()
  {
    this.selectedCity = string.Empty;
  }
  private void HandleCitySelection(string cityName)
  {
    this.selectedCity = cityName;
    SelectCityCallBack.InvokeAsync(cityName);
  }

  public void Dispose()
  {
    var guid = Guid.NewGuid();
    Console.WriteLine($"CityListComponent: {nameof(Dispose)} : {guid}");
  }
}