using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media;
using Project.Controller;
using Project.View;

namespace Project.View;

public partial class LoginPage : UserControl
{
    readonly AppController? _controller;
    public LoginPage()
    {
        InitializeComponent();
    }
        public LoginPage(AppController controller)
    {
        InitializeComponent();
        _controller = controller;
    }
    //gives loginname and password over to the appcontroller to compare the logins
    private async void LoginButtonOnClick(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
    {
        string? loginName = LoginNameBox.Text ??  string.Empty;
        string? loginPassword = LoginPasswordBox.Text ??  string.Empty;
        bool allowLogin = AppController.CompareLogin(loginName, loginPassword);
        var newMenuView = new MenuView();
        var newPopUp = new PopUp();
        if (allowLogin)
        {
            //show menuview
            newMenuView.Show();
        }
        else
        {
            newPopUp.Show();
            LoginNameBox.Text = string.Empty;
            LoginPasswordBox.Text = string.Empty;
        }
    }
    private async void NewUserButtonOnClick(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
    {
        var newLoginWindow = new NewLogin();
        newLoginWindow.Show();
    }
}