using System.Windows;
using System.Windows.Input;

namespace NexusShell.Helpers;

public static class NexusAppWindowHelper
{
    public static void HandleTitleBarMouseDown(Window window, MouseButtonEventArgs e)
    {
        if (e.ClickCount == 2)
        {
            ToggleMaximize(window);
            e.Handled = true;
            return;
        }

        if (e.ClickCount == 1 && e.ButtonState == MouseButtonState.Pressed)
        {
            try
            {
                window.DragMove();
            }
            catch (InvalidOperationException)
            {
                // DragMove throws if the mouse button is released before the call completes.
            }
        }
    }

    public static void Minimize(Window window) => window.WindowState = WindowState.Minimized;

    public static void ToggleMaximize(Window window)
    {
        window.WindowState = window.WindowState == WindowState.Maximized
            ? WindowState.Normal
            : WindowState.Maximized;
    }

    public static bool GetIsMaximized(Window window) =>
        window.WindowState == WindowState.Maximized;
}
