using System;
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.Empty;
        string password = NewLoginPasswordBox.Text?.Trim() ?? string.Empty;
        string email = NewLoginEmailBox.Text?.Trim() ?? string.Empty;
        //test inputs:
        bool masterLoginPasswordBool = InputSanitizer.MasterLoginPasswordBool(password);
        bool masterLoginEmailBool = InputSanitizer.MasterLoginEmailBool(email);
        bool masterLoginNameBool = InputSanitizer.MasterLoginNameBool(username);
        //give strings to appcontroller and keep working on them there
        if (masterLoginPasswordBool && masterLoginEmailBool && masterLoginNameBool)
        {
            AppController.NewLoginSave(username, password, email);
            Close();
        }
        else
        {
            NewLoginUsernameBox.Text = string.Empty;
            NewLoginPasswordBox.Text = string.Empty;
            NewLoginEmailBox.Text = string.Empty;
            var ShowPopup = new PopUp();
            ShowPopup.ShowDialog(this);
        }
    }
    
    private void NewLoginCancelOnClick(object? sender, RoutedEventArgs e)
    {
        Close();
    }
}