using MangaReader.WinUI.ViewModels;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System.Threading;
using System.Threading.Tasks;

namespace MangaReader.WinUI.Views;

public sealed partial class SearchView : Page
{
    private readonly SearchViewModel viewModel;

    public SearchView()
    {
        InitializeComponent();

        viewModel = (SearchViewModel)DataContext;
    }

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        if (sender is not Button button)
            return;

        if (button.Tag is not ObservableMangaSearchResult searchResult)
            return;

        await viewModel.ImportAsync(searchResult, CancellationToken.None);
    }
}