using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Microsoft.EntityFrameworkCore;
using tiron_demo.Context;
using tiron_demo.Models;

namespace tiron_demo;

public partial class PartnersWindow : Window
{
    public PartnersWindow()
    {
        InitializeComponent();

        Partners.ItemsSource = Helper.context.Partners.Include(x => x.TypeNavigation).Include(x => x.PartnerProducts);
    }

    private void Button_Click_Add(object? sender, RoutedEventArgs args)
    {
        AddPartner partnerWindow = new AddPartner();
        partnerWindow.Show();
        Close();
    }

    private void Button_Click_Back(object? sender, RoutedEventArgs args)
    {
        MainWindow mainWindow = new MainWindow();
        mainWindow.Show();
        Close();
    }

    private void ListBox_DoubleTapped(object? sender, RoutedEventArgs args)
    {
        var partner = Partners.SelectedItem as Partner;

        if (partner != null)
        {
            AddPartner partnerWindow = new AddPartner(partner);
            partnerWindow.Show();
            Close();
        }
    }

    private void Button_Click_History(object? sender, RoutedEventArgs args)
    {
        if (Partners.SelectedItem != null)
        {
            Partner partner = Partners.SelectedItem as Partner;
            History history = new History(this, partner.Id, 0);
            history.Show();
            Close();
        }
    }
}