using System;
using System.Globalization;
using Avalonia.Controls;
using Avalonia.Data.Converters;

namespace detect.gui.Converters;

public class WindowStateConverter : IValueConverter
{
    public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        var state = value is WindowState windowState ? windowState : WindowState.Normal;
        var param = int.Parse((string?)parameter ?? string.Empty);
        switch (state)
        {
            case WindowState.Maximized when param == 1:
            case WindowState.Normal when param == 2:
                return true;
            case WindowState.Minimized:
            case WindowState.FullScreen:
            default:
                return false;
        }
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        return value;
    }
}