#if WINDOWS
using Microsoft.UI.Windowing;
using Microsoft.UI;
using WinRT.Interop;

namespace SilverOS.Welcome.App;

public static class WindowExtensions
{
    // Borderless, fullscreen, non-closable kiosk window. Returns true when applied.
    // Defensive: HandlerChanged can fire before the HWND/AppWindow is ready, so we
    // bail out cleanly and rely on a later HandlerChanged to apply it.
    public static bool ApplyKioskChrome(this Microsoft.UI.Xaml.Window winuiWindow)
    {
        var hwnd = WindowNative.GetWindowHandle(winuiWindow);
        if (hwnd == IntPtr.Zero) return false;
        var id = Win32Interop.GetWindowIdFromWindow(hwnd);
        var appWindow = AppWindow.GetFromWindowId(id);
        if (appWindow is null) return false;
        // FullScreen presenter is borderless (no title bar) by nature — simpler and
        // more reliable than toggling OverlappedPresenter border/title-bar flags.
        appWindow.SetPresenter(AppWindowPresenterKind.FullScreen);
        appWindow.Closing += (s, e) => e.Cancel = true;
        return true;
    }
}
#endif
