using System;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Markup.Xaml;

namespace VeloeMinecraftLauncher.Views;

public partial class SettingsView : UserControl
{
    public SettingsView()
    {
        InitializeComponent();
        this.FindControl<NumericUpDown>("GameWidthEdit").AddHandler(TextInputEvent, NumericUpDown_TextInput, Avalonia.Interactivity.RoutingStrategies.Tunnel);
        this.FindControl<NumericUpDown>("GameHeightEdit").AddHandler(TextInputEvent, NumericUpDown_TextInput, Avalonia.Interactivity.RoutingStrategies.Tunnel);
        this.FindControl<NumericUpDown>("MaxRamEdit").AddHandler(TextInputEvent, NumericUpDown_TextInput, Avalonia.Interactivity.RoutingStrategies.Tunnel);
        this.FindControl<NumericUpDown>("MaxLogEdit").AddHandler(TextInputEvent, NumericUpDown_TextInput, Avalonia.Interactivity.RoutingStrategies.Tunnel);
    }

    private int MaxGameWidth => 1920;//Screens.All.Select(x => x.Bounds.Width).Max();

    private int MaxGameHeight => 1080;//Screens.All.Select(x => x.Bounds.Height).Max();

    private long MaxRam => GC.GetGCMemoryInfo().TotalAvailableMemoryBytes / 1024 / 1024;

    private void NumericUpDown_TextInput(object? sender, TextInputEventArgs e)
    {
        e.Handled = !e.Text?.All(x => char.IsDigit(x)) ?? false;
    }
}