using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media;
using Project.Controller;
using Project.Model;
using Project.Persistence;

namespace Project.View;

public partial class NewLogin : Window
{
    readonly AppController? _controller;
    public NewLogin()
    {
        InitializeComponent();
    }

    public NewLogin(AppController controller)
    {
        InitializeComponent();
        _controller = controller;
    }

    private void NewLoginSaveOnClick(object? sender, RoutedEventArgs e)
    {
        string username = NewLoginUsernameBox.Text?.Trim();
        string password = NewLoginPasswordBox.Text?.Trim();
        string email = NewLoginEmailBox.Text?.Trim();
        string hashedPassword = ShaHash.HashPassword(password);
        var user = new Model.NewUser(username, hashedPassword, email);
        SQLite.SaveUser(user);

        Close();
    }
    
    private void NewLoginCancelOnClick(object? sender, RoutedEventArgs e)
    {
        Close();
    }
}