namespace GameAtlas.Views;

using GameAtlas.Models;
using System.Collections.ObjectModel;

public partial class PageParcourir : ContentPage
{

    public Manager ParcourirManager => (App.Current as App).MyManager;
    public PageParcourir()
	{
		InitializeComponent();
        BindingContext = ParcourirManager;
    }

    async void OnGame_Tapped(System.Object sender, EventArgs e)
    {
        var selectedjeu = (sender as ImageButton)?.BindingContext as Jeu;
        if (selectedjeu != null)
        {
            
            await Navigation.PushAsync(new PageJeu(selectedjeu));
        }
       
    }

    async void Back_Tapped(System.Object sender, Microsoft.Maui.Controls.TappedEventArgs e)
    {
        await Navigation.PopAsync();
    }

    private void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
    {
        if(string.IsNullOrWhiteSpace(e.NewTextValue))
        {
            searchResults.ItemsSource = ParcourirManager.ListJeux;
        }
        else
        {
            searchResults.ItemsSource = ParcourirManager.ListJeux.Where(i => i.Nom.ToLower().Contains(e.NewTextValue.ToLower()));
        }
    }
}