using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Markup;
using Microsoft.UI.Xaml.Media;
using Sonex.Client.Helpers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;

using Windows.Graphics;
using Windows.System;
using Windows.UI;
using Windows.UI.Core;
using WinRT.Interop;

namespace Sonex.Client.AppWindows
{
    public sealed partial class LoginWindow : Window
    {
        // ===== rozmiar projektowy w DIP (XAML units) =====
        private const double TargetWidthDip = 680;
        private const double TargetHeightDip = 420;

        // ===== DPI hook (WM_DPICHANGED) =====
        private IntPtr _hwnd;
        private WndProcDelegate? _newWndProc;
        private IntPtr _oldWndProc;

        private const int WM_DPICHANGED = 0x02E0;
        private const int GWL_WNDPROC = -4;

        private int _loginAttempts = 0;

        public LoginWindow()
        {
            InitializeComponent();

            if (AppWindow.Presenter is OverlappedPresenter presenter)
            {
                presenter.IsMaximizable = false;
                presenter.IsResizable = false;
                presenter.SetBorderAndTitleBar(true, true);
            }

            ExtendsContentIntoTitleBar = true;
            SetTitleBar(_TitleBar);

            _hwnd = WindowNative.GetWindowHandle(this);
            HookWndProc();

            // DPI-aware: DIP->PX + center
            ApplyFixedSizeDip(center: true);

            AppWindow.Changed += AppWindow_Changed;

            _VersionInfo.Text = $"Version {AppInfo.InformationalVersion.Trim()}";
            string iconPath = System.IO.Path.Combine(AppContext.BaseDirectory, "Assets\\AppIcon.ico");
            AppWindow.SetIcon(iconPath);
            string ThemeName = Config.GetStringValue("ThemeName", "Auto");
            string ThemeLight = Config.GetStringValue("ThemeLight", "Auto");
            SetThemeLight(ThemeLight);
            SetThemeMode(ThemeName);
        }
        private string[] temes= { "Default", "Autumn", "Christmas", "Easter", "Halloween", "Koningsdag", "Labor Day", "New Year", "Spring", "Summer", "Valentine", "Winter", "Galaga1981" };
        private int temeIndex = 0;
        private void RootGrid_KeyDown(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e)
        {
            Debug.WriteLine(e.Key);
            if (e.Key == VirtualKey.PageUp)
            {
                temeIndex++;
                if (temeIndex >= temes.Length) temeIndex = 0;
            }
            else if (e.Key == VirtualKey.PageDown)
            {
                temeIndex--;
                if (temeIndex < 0) temeIndex = temes.Length - 1;
            }
            if (e.Key == VirtualKey.Pause)
            {
                if(RootGrid.ActualTheme == ElementTheme.Light)
                {
                    SetThemeLight("Dark");
                }
                else
                {
                    SetThemeLight("Light");
                }
            }
                SetThemeMode(temes[temeIndex]);
        }

        // ===== okno: zabezpieczenie przed maximize =====
        private void AppWindow_Changed(AppWindow sender, AppWindowChangedEventArgs args)
        {
            if (sender.Presenter is OverlappedPresenter presenter)
            {
                if (presenter.State == OverlappedPresenterState.Maximized)
                    presenter.Restore();
            }
        }

        // ===== DPI-aware rozmiar =====
        private void ApplyFixedSizeDip(bool center)
        {
            uint dpi = GetDpiForWindow(_hwnd);

            int pxW = DipToPx(TargetWidthDip, dpi);
            int pxH = DipToPx(TargetHeightDip, dpi);

            AppWindow.Resize(new SizeInt32(pxW, pxH));

            if (center)
                AppWindowsHelper.CenterWindow(this, pxW, pxH);
        }

        private static int DipToPx(double dip, uint dpi)
            => (int)Math.Round(dip * dpi / 96.0);

        // ===== WndProc hook: WM_DPICHANGED =====
        private void HookWndProc()
        {
            _newWndProc = WndProc;
            _oldWndProc = SetWindowLongPtr(_hwnd, GWL_WNDPROC,
                Marshal.GetFunctionPointerForDelegate(_newWndProc));
        }

        private IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam)
        {
            if (msg == WM_DPICHANGED)
            {
                // DPI się zmieniło -> przelicz PX wg DIP (nie centruj, bo to by “skakało”)
                ApplyFixedSizeDip(center: false);
            }

            return CallWindowProc(_oldWndProc, hWnd, msg, wParam, lParam);
        }

        private delegate IntPtr WndProcDelegate(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

        [DllImport("user32.dll")]
        private static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr newProc);

        [DllImport("user32.dll")]
        private static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

        [DllImport("user32.dll")]
        private static extern uint GetDpiForWindow(IntPtr hwnd);

        private void _ThemeLight_Change(object sender, RoutedEventArgs e)
        {
            RadioMenuFlyoutItem? button = sender as RadioMenuFlyoutItem;
            if (button == null) return;
            string text = button.Text;

            Config.SetValue("ThemeLight", text);
            SetThemeLight(text);
            //((FrameworkElement)Content).UpdateLayout();
        }
        private void SetThemeLight(string themeLight)
        {
            switch (themeLight)
            {
                case "Auto": RootGrid.RequestedTheme = ElementTheme.Default; break;
                case "Dark": RootGrid.RequestedTheme = ElementTheme.Dark;  break;
                case "Light": RootGrid.RequestedTheme = ElementTheme.Light; break;
                default: RootGrid.RequestedTheme = ElementTheme.Default; break;
            }
            var theme = RootGrid.ActualTheme;
            if (theme == ElementTheme.Dark)
                ApplyTitleBarTheme(this, dark: true);
            else
                ApplyTitleBarTheme(this, dark: false);

            RootGrid.UpdateLayout();
        }
        public static void ApplyTitleBarTheme(Window window, bool dark)
        {
            var hwnd = WindowNative.GetWindowHandle(window);
            var id = Win32Interop.GetWindowIdFromWindow(hwnd);
            var appWindow = AppWindow.GetFromWindowId(id);

            if (appWindow.TitleBar is null) return;

            // własny pasek (opcjonalnie)
            // appWindow.TitleBar.ExtendsContentIntoTitleBar = true;

            if (dark)
            {
                appWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
                appWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;

                appWindow.TitleBar.ButtonForegroundColor = Colors.White;
                appWindow.TitleBar.ButtonInactiveForegroundColor = Color.FromArgb(255, 180, 180, 180);

                appWindow.TitleBar.ButtonHoverBackgroundColor = Color.FromArgb(255, 45, 45, 45);
                appWindow.TitleBar.ButtonHoverForegroundColor = Colors.White;

                appWindow.TitleBar.ButtonPressedBackgroundColor = Color.FromArgb(255, 30, 30, 30);
                appWindow.TitleBar.ButtonPressedForegroundColor = Colors.White;
            }
            else
            {
                appWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
                appWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;

                appWindow.TitleBar.ButtonForegroundColor = Colors.Black;
                appWindow.TitleBar.ButtonInactiveForegroundColor = Color.FromArgb(255, 120, 120, 120);

                appWindow.TitleBar.ButtonHoverBackgroundColor = Color.FromArgb(255, 230, 230, 230);
                appWindow.TitleBar.ButtonHoverForegroundColor = Colors.Black;

                appWindow.TitleBar.ButtonPressedBackgroundColor = Color.FromArgb(255, 210, 210, 210);
                appWindow.TitleBar.ButtonPressedForegroundColor = Colors.Black;
            }
        }

        private void _ThemeMode_Change(object sender, RoutedEventArgs e)
        {
            RadioMenuFlyoutItem? button = sender as RadioMenuFlyoutItem;
            if (button == null) return;
            string text = button.Text;

            Config.SetValue("ThemeName", text);
            SetThemeMode(text);
        }

        private void SetThemeMode(string themeName)
        {
            _BackgroundAnimation.ResetParametersToDefaults();
            switch (themeName)
            {
                case "Auto": AutoMode(); break;
                case "Default": DefaultMode(); break;
                case "Autumn": AutumnMode(); break;
                case "Christmas": ChristmasMode(); break;
                case "Easter": EasterMode(); break;
                case "Halloween": HalloweenMode(); break;
                case "Koningsdag": KoningsdagMode(); break;
                case "Labor Day": LaborDayMode(); break;
                case "New Year": NewYearMode(); break;
                case "Spring": SpringMode(); break;
                case "Summer": SummerMode(); break;
                case "Valentine": ValentineMode(); break;
                case "Winter": WinterMode(); break;
                case "Galaga1981": Galaga1981Mode(); break;
                default: AutoMode(); break;

            }
            var _ = _BackgroundAnimation.ReloadAllAsync();

        }


        private void AutoMode()
        {
            var today = DateTime.Today;
            int year = today.Year;

            static bool InRange(DateTime d, DateTime from, DateTime to) => d >= from && d <= to;

            // ===== NEW YEAR =====
            // 27 grudnia → 3 stycznia
            var newYearStart = new DateTime(year - 1, 12, 27);
            var newYearEnd = new DateTime(year, 1, 3);

            if (InRange(today, newYearStart, newYearEnd))
            {
                NewYearMode();
                return;
            }

            // ===== VALENTINE =====
            var valentine = new DateTime(year, 2, 14);
            if (InRange(today, valentine.AddDays(-7), valentine))
            {
                ValentineMode();
                return;
            }

            // ===== EASTER =====
            var easter = GetEasterSunday();
            if (InRange(today, easter.AddDays(-7), easter.AddDays(1)))
            {
                EasterMode();
                return;
            }

            // ===== KONINGSDAG =====
            var koningsdag = new DateTime(year, 4, 27);
            if (koningsdag.DayOfWeek == DayOfWeek.Sunday)
                koningsdag = koningsdag.AddDays(-1);

            if (InRange(today, koningsdag.AddDays(-7), koningsdag))
            {
                KoningsdagMode();
                return;
            }

            // ===== LABOR DAY =====
            var labor = new DateTime(year, 5, 1);
            if (InRange(today, labor.AddDays(-7), labor))
            {
                LaborDayMode();
                return;
            }

            // ===== HALLOWEEN =====
            var halloween = new DateTime(year, 10, 31);
            if (InRange(today, halloween.AddDays(-7), halloween))
            {
                HalloweenMode();
                return;
            }

            // ===== CHRISTMAS =====
            var christmasStart = new DateTime(year, 12, 25).AddDays(-7);
            var christmasEnd = new DateTime(year, 12, 26);

            if (InRange(today, christmasStart, christmasEnd))
            {
                ChristmasMode();
                return;
            }

            // ===== WINTER =====
            var winter = new DateTime(year, 12, 1);
            if (InRange(today, easter.AddDays(-7), easter.AddDays(1)))
            {
                WinterMode();
                return;
            }

            // ===== SPRING =====
            var spring = new DateTime(year, 3, 1);
            if (InRange(today, easter.AddDays(-7), easter.AddDays(1)))
            {
                SpringMode();
                return;
            }

            // ===== SUMMER =====
            var summer = new DateTime(year, 6, 1);
            if (InRange(today, easter.AddDays(-7), easter.AddDays(1)))
            {
                SummerMode();
                return;
            }

            // ===== AUTUMN =====
            var autumn = new DateTime(year, 9, 1);
            if (InRange(today, easter.AddDays(-7), easter.AddDays(1)))
            {
                AutumnMode();
                return;
            }

            DefaultMode();
        }

        public static DateTime GetEasterSunday()
        {
            int year = DateTime.Now.Year;
            // Meeus/Jones/Butcher (Gregorian)
            int a = year % 19;
            int b = year / 100;
            int c = year % 100;
            int d = b / 4;
            int e = b % 4;
            int f = (b + 8) / 25;
            int g = (b - f + 1) / 3;
            int h = (19 * a + b - d - g + 15) % 30;
            int i = c / 4;
            int k = c % 4;
            int l = (32 + 2 * e + 2 * i - h - k) % 7;
            int m = (a + 11 * h + 22 * l) / 451;

            int month = (h + l - 7 * m + 114) / 31;          // 3=marzec, 4=kwiecień
            int day = ((h + l - 7 * m + 114) % 31) + 1;

            return new DateTime(year, month, day);
        }

        private void DefaultMode()
        {

            _BackgroundAnimation.BackgroundImageUriLight = "Assets/LoginWindowsBackGround/DefaultLight.png";
            _BackgroundAnimation.BackgroundImageUriDark = "Assets/LoginWindowsBackGround/DefaultDark.png";
            _BackgroundAnimation.IconUris = GenerateIconUris("Assets/Icons/default", 33, ".png");
            _BackgroundAnimation.FillNodes = true;
            _BackgroundAnimation.DrawEdges = true;
            _BackgroundAnimation.AppearWidth = 650;
            _BackgroundAnimation.ScrollSpeed = 21;
            _BackgroundAnimation.NodeSpawnRate = 20;
            _BackgroundAnimation.MaxNodes = 20;
            _BackgroundAnimation.MaxNodeRadius = 32;
            _BackgroundAnimation.CollisionPadding = 48;
            _BackgroundAnimation.CollisionIterations = 5;
            _BackgroundAnimation.NodeColorA = Color.FromArgb(255, 184, 196, 203);
            _BackgroundAnimation.NodeColorB = Color.FromArgb(255, 246, 208, 100);
            _BackgroundAnimation.ColorAWeight = 0.7d;
            _BackgroundAnimation.IconMinDiameter = 28;
            _BackgroundAnimation.IconScale = 0.5d;
            _BackgroundAnimation.TopLeftY = -100d;
            _BackgroundAnimation.BottomLeftY = 240d;
            _BackgroundAnimation.TopRightY = 0d;
            _BackgroundAnimation.BottomRightY = 420d;
            _BackgroundAnimation.InvisibleBouncePad = 20d;
            _BackgroundAnimation.BounceDamping = 0.97d;

        }

        private void Galaga1981Mode()
        {

            _BackgroundAnimation.BackgroundImageUriLight = "Assets/LoginWindowsBackGround/Galaga1981Light.png";
            _BackgroundAnimation.BackgroundImageUriDark = "Assets/LoginWindowsBackGround/Galaga1981Dark.png";
            _BackgroundAnimation.IconUris = GenerateIconUris("Assets/Icons/ship", 12, ".png");
            _BackgroundAnimation.FillNodes = false;
            _BackgroundAnimation.DrawEdges = false;
            _BackgroundAnimation.AppearWidth = 300;
            _BackgroundAnimation.ScrollSpeed = 35;
            _BackgroundAnimation.NodeSpawnRate = 20;
            _BackgroundAnimation.MaxNodes = 16;
            _BackgroundAnimation.MaxNodeRadius = 32;
            _BackgroundAnimation.MinNodeRadius = 32;
            _BackgroundAnimation.MaxLinksPerNode = 16;
            _BackgroundAnimation.CollisionPadding = 32;
            _BackgroundAnimation.CollisionIterations = 5;
            _BackgroundAnimation.NodeColorA = Color.FromArgb(255, 184, 196, 203);
            _BackgroundAnimation.NodeColorB = Color.FromArgb(255, 246, 208, 100);
            _BackgroundAnimation.ColorAWeight = 0.7d;
            _BackgroundAnimation.IconMinDiameter = 28;
            _BackgroundAnimation.IconScale = 0.5d;
            _BackgroundAnimation.TopLeftY = -100d;
            _BackgroundAnimation.BottomLeftY = 240d;
            _BackgroundAnimation.TopRightY = 0d;
            _BackgroundAnimation.BottomRightY = 420d;
            _BackgroundAnimation.InvisibleBouncePad = 20d;
            _BackgroundAnimation.BounceDamping = 0.97d;

        }

        private void _Login_Click(object sender, RoutedEventArgs e)
        {
            _Login.Content = "Click";
            temeIndex++;
            if (temeIndex >= temes.Length) 
                temeIndex = 0;
            SetThemeMode(temes[temeIndex]);

            //LaborDayMode();
            //_BackgroundAnimation.ReloadAllAsync();
        }


        // ===== tryby tła =====

        public void HalloweenMode()
        {
            _BackgroundAnimation.FillNodes = false;
            _BackgroundAnimation.DrawEdges = false;
            _BackgroundAnimation.BackgroundImageUriLight = "Assets/LoginWindowsBackGround/HalloweenLight.png";
            _BackgroundAnimation.BackgroundImageUriDark = "Assets/LoginWindowsBackGround/HalloweenDark.png";
            _BackgroundAnimation.IconScale = 1;
            _BackgroundAnimation.MinNodeRadius = 16;
            _BackgroundAnimation.IconMinDiameter = 32;
            _BackgroundAnimation.MaxNodeRadius = 32;
            _BackgroundAnimation.AppearWidth = 1200;
            _BackgroundAnimation.IconUris = GenerateIconUris("Assets/Icons/ghost", 11, ".png");


            _BackgroundAnimation.ScrollSpeed = 21;
            _BackgroundAnimation.NodeSpawnRate = 20;
            _BackgroundAnimation.MaxNodes = 10;
            _BackgroundAnimation.CollisionPadding = 48;
            _BackgroundAnimation.CollisionIterations = 5;
            _BackgroundAnimation.NodeColorA = Color.FromArgb(255, 184, 196, 203);
            _BackgroundAnimation.NodeColorB = Color.FromArgb(255, 246, 208, 100);
            _BackgroundAnimation.ColorAWeight = 0.7d;
            _BackgroundAnimation.TopLeftY = -100d;
            _BackgroundAnimation.BottomLeftY = 240d;
            _BackgroundAnimation.TopRightY = 0d;
            _BackgroundAnimation.BottomRightY = 420d;
            _BackgroundAnimation.InvisibleBouncePad = 20d;
            _BackgroundAnimation.BounceDamping = 0.97d;
            _BackgroundAnimation.NodesOpocity = false;

        }

        public void ValentineMode()
        {
            _BackgroundAnimation.FillNodes = false;
            _BackgroundAnimation.DrawEdges = false;
            _BackgroundAnimation.BackgroundImageUriLight = "Assets/LoginWindowsBackGround/ValentineLight.png";
            _BackgroundAnimation.BackgroundImageUriDark = "Assets/LoginWindowsBackGround/ValentineDark.png";
            _BackgroundAnimation.IconScale = 1;
            _BackgroundAnimation.MinNodeRadius = 32;
            _BackgroundAnimation.IconMinDiameter = 32;
            _BackgroundAnimation.MaxNodeRadius = 64;
            _BackgroundAnimation.AppearWidth = 800;
            _BackgroundAnimation.ScrollSpeed = 12;
            _BackgroundAnimation.MaxNodes = 6;
            _BackgroundAnimation.IconUris = GenerateIconUris("Assets/Icons/heart", 8, ".png");

            _BackgroundAnimation.NodeSpawnRate = 20;
            _BackgroundAnimation.CollisionPadding = 48;
            _BackgroundAnimation.CollisionIterations = 5;
            _BackgroundAnimation.NodeColorA = Color.FromArgb(255, 184, 196, 203);
            _BackgroundAnimation.NodeColorB = Color.FromArgb(255, 246, 208, 100);
            _BackgroundAnimation.ColorAWeight = 0.7d;
            _BackgroundAnimation.TopLeftY = -100d;
            _BackgroundAnimation.BottomLeftY = 240d;
            _BackgroundAnimation.TopRightY = 0d;
            _BackgroundAnimation.BottomRightY = 420d;
            _BackgroundAnimation.InvisibleBouncePad = 20d;
            _BackgroundAnimation.BounceDamping = 0.97d;

        }

        public void ChristmasMode()
        {
            _BackgroundAnimation.IconUris = GenerateIconUris("Assets/Icons/snowflakes", 5, ".png");
            _BackgroundAnimation.FillNodes = false;
            _BackgroundAnimation.DrawEdges = false;
            _BackgroundAnimation.BackgroundImageUriLight = "Assets/LoginWindowsBackGround/ChristmasLight.png";
            _BackgroundAnimation.BackgroundImageUriDark = "Assets/LoginWindowsBackGround/ChristmasDark.png";
            _BackgroundAnimation.IconScale = 1;
            _BackgroundAnimation.MinNodeRadius = 8;
            _BackgroundAnimation.MaxNodeRadius = 14;
            _BackgroundAnimation.IconMinDiameter = 8;
            _BackgroundAnimation.AppearWidth = 800;
            _BackgroundAnimation.ScrollSpeed = 35;
            _BackgroundAnimation.MaxNodes = 25;
            _BackgroundAnimation.NodeSpawnRate = 20;


            _BackgroundAnimation.CollisionPadding = 48;
            _BackgroundAnimation.CollisionIterations = 5;
            _BackgroundAnimation.NodeColorA = Color.FromArgb(255, 184, 196, 203);
            _BackgroundAnimation.NodeColorB = Color.FromArgb(255, 246, 208, 100);
            _BackgroundAnimation.TopLeftY = -100d;
            _BackgroundAnimation.BottomLeftY = 240d;
            _BackgroundAnimation.TopRightY = 0d;
            _BackgroundAnimation.BottomRightY = 420d;
            _BackgroundAnimation.InvisibleBouncePad = 20d;
            _BackgroundAnimation.BounceDamping = 0.97d;
            _BackgroundAnimation.ColorAWeight = 0.7d;
        }

        public void EasterMode()
        {
            _BackgroundAnimation.FillNodes = false;
            _BackgroundAnimation.DrawEdges = false;
            _BackgroundAnimation.BackgroundImageUriLight = "Assets/LoginWindowsBackGround/EasterLight.png";
            _BackgroundAnimation.BackgroundImageUriDark = "Assets/LoginWindowsBackGround/EasterDark.png";
            _BackgroundAnimation.IconScale = 1;
            _BackgroundAnimation.MinNodeRadius = 10;
            _BackgroundAnimation.MaxNodeRadius = 22;
            _BackgroundAnimation.IconMinDiameter = 8;
            _BackgroundAnimation.AppearWidth = 800;
            _BackgroundAnimation.ScrollSpeed = 40;
            _BackgroundAnimation.MaxNodes = 5;
            _BackgroundAnimation.NodeSpawnRate = 5;
            _BackgroundAnimation.NodesOpocity = true;
            _BackgroundAnimation.PulseIconWidth = true;
            _BackgroundAnimation.PulseIconWidthAmplitude = 0.2f;
            _BackgroundAnimation.PulseIconWidthFrequency = 5;
            _BackgroundAnimation.IconUris = GenerateIconUris("Assets/Icons/butterfly", 2, ".png");


            _BackgroundAnimation.CollisionPadding = 48;
            _BackgroundAnimation.CollisionIterations = 5;
            _BackgroundAnimation.NodeColorA = Color.FromArgb(255, 184, 196, 203);
            _BackgroundAnimation.NodeColorB = Color.FromArgb(255, 246, 208, 100);
            _BackgroundAnimation.TopLeftY = -100d;
            _BackgroundAnimation.BottomLeftY = 240d;
            _BackgroundAnimation.TopRightY = 0d;
            _BackgroundAnimation.BottomRightY = 420d;
            _BackgroundAnimation.InvisibleBouncePad = 20d;
            _BackgroundAnimation.BounceDamping = 0.97d;
            _BackgroundAnimation.ColorAWeight = 0.7d;
        }

        public void KoningsdagMode()
        {
            _BackgroundAnimation.FillNodes = false;
            _BackgroundAnimation.DrawEdges = false;
            _BackgroundAnimation.BackgroundImageUriLight = "Assets/LoginWindowsBackGround/KoningsdagLight.png";
            _BackgroundAnimation.BackgroundImageUriDark = "Assets/LoginWindowsBackGround/KoningsdagDark.png";
            _BackgroundAnimation.IconScale = 1;
            _BackgroundAnimation.MinNodeRadius = 2;
            _BackgroundAnimation.MaxNodeRadius = 10;
            _BackgroundAnimation.IconMinDiameter = 4;
            _BackgroundAnimation.AppearWidth = 1;
            _BackgroundAnimation.ScrollSpeed = 60;
            _BackgroundAnimation.CollisionPadding = 24;
            _BackgroundAnimation.MaxNodes = 80;
            _BackgroundAnimation.NodeSpawnRate = 60;
            _BackgroundAnimation.NodesOpocity = true;
            _BackgroundAnimation.IconUris = GenerateIconUris("Assets/Icons/confetti", 5, ".png");
            _BackgroundAnimation.RandomIconRotation = true;


            _BackgroundAnimation.CollisionIterations = 5;
            _BackgroundAnimation.NodeColorA = Color.FromArgb(255, 184, 196, 203);
            _BackgroundAnimation.NodeColorB = Color.FromArgb(255, 246, 208, 100);
            _BackgroundAnimation.TopLeftY = -100d;
            _BackgroundAnimation.BottomLeftY = 240d;
            _BackgroundAnimation.TopRightY = 0d;
            _BackgroundAnimation.BottomRightY = 420d;
            _BackgroundAnimation.InvisibleBouncePad = 20d;
            _BackgroundAnimation.BounceDamping = 0.97d;
            _BackgroundAnimation.ColorAWeight = 0.7d;
        }

        public void LaborDayMode()
        {
            _BackgroundAnimation.FillNodes = false;
            _BackgroundAnimation.DrawEdges = false;
            _BackgroundAnimation.BackgroundImageUriLight = "Assets/LoginWindowsBackGround/LaborDayLight.png";
            _BackgroundAnimation.BackgroundImageUriDark = "Assets/LoginWindowsBackGround/LaborDayDark.png";
            _BackgroundAnimation.IconScale = 1;
            _BackgroundAnimation.MinNodeRadius = 2;
            _BackgroundAnimation.MaxNodeRadius = 10;
            _BackgroundAnimation.IconMinDiameter = 4;
            _BackgroundAnimation.AppearWidth = 1;
            _BackgroundAnimation.TopLeftY = 100;
            _BackgroundAnimation.BottomLeftY = 600;
            _BackgroundAnimation.ScrollSpeed = 60;
            _BackgroundAnimation.CollisionPadding = 24;
            _BackgroundAnimation.MaxNodes = 80;
            _BackgroundAnimation.NodeSpawnRate = 60;
            _BackgroundAnimation.NodesOpocity = false;
            _BackgroundAnimation.IconUris = GenerateIconUris("Assets/Icons/confetti", 13, ".png");
            _BackgroundAnimation.RandomIconRotation = true;

            _BackgroundAnimation.CollisionIterations = 5;
            _BackgroundAnimation.NodeColorA = Color.FromArgb(255, 184, 196, 203);
            _BackgroundAnimation.NodeColorB = Color.FromArgb(255, 246, 208, 100);
            _BackgroundAnimation.TopRightY = 0d;
            _BackgroundAnimation.BottomRightY = 420d;
            _BackgroundAnimation.InvisibleBouncePad = 20d;
            _BackgroundAnimation.BounceDamping = 0.97d;
            _BackgroundAnimation.ColorAWeight = 0.7d;
        }


        public void NewYearMode()
        {
            _BackgroundAnimation.FillNodes = false;
            _BackgroundAnimation.DrawEdges = false;
            _BackgroundAnimation.BackgroundImageUriLight = "Assets/LoginWindowsBackGround/NewYearLight.png";
            _BackgroundAnimation.BackgroundImageUriDark = "Assets/LoginWindowsBackGround/NewYearDark.png";
            _BackgroundAnimation.IconScale = 1;
            _BackgroundAnimation.MinNodeRadius = 10;
            _BackgroundAnimation.MaxNodeRadius = 36;
            _BackgroundAnimation.ScrollSpeed = 11;
            _BackgroundAnimation.CollisionPadding = 4;

            _BackgroundAnimation.IconMinDiameter = 2;
            _BackgroundAnimation.AppearWidth = 800;
            _BackgroundAnimation.MaxNodes = 10;
            _BackgroundAnimation.NodeSpawnRate = 5;
            _BackgroundAnimation.TopLeftY = 150;
            _BackgroundAnimation.BottomLeftY = 350;
            _BackgroundAnimation.TopRightY = 150;
            _BackgroundAnimation.BottomRightY = 300;
            _BackgroundAnimation.IconUris = GenerateIconUris("Assets/Icons/firework", 9, "b.png");
            _BackgroundAnimation.FireworkIconBurst = true;
            _BackgroundAnimation.FireworkOffDuration = 7d;
            _BackgroundAnimation.FireworkExpandDuration = 0.5d;
            _BackgroundAnimation.FireworkHoldDuration = 0.0d;
            _BackgroundAnimation.FireworkFadeOutDuration = 2d;
            _BackgroundAnimation.FireworkTargetScale = 2d;
            _BackgroundAnimation.FireworkFlareAmplitude = 1d;
            _BackgroundAnimation.FireworkFlareFrequency = 40d;
            _BackgroundAnimation.CollisionPositionCorrection = 1;
            _BackgroundAnimation.CollisionMaxCorrectionPx = 20;
            _BackgroundAnimation.CollisionImpulseDamping = 0;
            _BackgroundAnimation.CollisionTangentFriction = 0;
            _BackgroundAnimation.MaxLinksPerNode = 25;
            _BackgroundAnimation.MinLinksPerNode = 25;

            _BackgroundAnimation.CollisionIterations = 5;
            _BackgroundAnimation.NodeColorA = Color.FromArgb(255, 184, 196, 203);
            _BackgroundAnimation.NodeColorB = Color.FromArgb(255, 246, 208, 100);
            _BackgroundAnimation.ColorAWeight = 0.7d;
            _BackgroundAnimation.InvisibleBouncePad = 20d;
            _BackgroundAnimation.BounceDamping = 0.97d;
        }
        public void AutumnMode()
        {
            _BackgroundAnimation.FillNodes = false;
            _BackgroundAnimation.DrawEdges = false;
            _BackgroundAnimation.BackgroundImageUriLight = "Assets/LoginWindowsBackGround/AutumnLight.png";
            _BackgroundAnimation.BackgroundImageUriDark = "Assets/LoginWindowsBackGround/AutumnDark.png";
            _BackgroundAnimation.IconScale = 1;
            _BackgroundAnimation.MinNodeRadius = 12;
            _BackgroundAnimation.MaxNodeRadius = 32;
            _BackgroundAnimation.IconMinDiameter = 4;
            _BackgroundAnimation.AppearWidth = 800;
            _BackgroundAnimation.ScrollSpeed = 35;
            _BackgroundAnimation.CollisionPadding = 42;
            _BackgroundAnimation.MaxNodes = 10;
            _BackgroundAnimation.NodeSpawnRate = 20;
            _BackgroundAnimation.NodesOpocity = false;
            _BackgroundAnimation.IconUris = GenerateIconUris("Assets/Icons/leaf", 29, ".png");
            _BackgroundAnimation.RandomIconRotation = false;
            _BackgroundAnimation.MaxLinksPerNode = 1;
            _BackgroundAnimation.MinLinksPerNode = 1;
            _BackgroundAnimation.CollisionIterations = 50;

            _BackgroundAnimation.NodeColorA = Color.FromArgb(255, 184, 196, 203);
            _BackgroundAnimation.NodeColorB = Color.FromArgb(255, 246, 208, 100);
            _BackgroundAnimation.TopLeftY = -100d;
            _BackgroundAnimation.BottomLeftY = 240d;
            _BackgroundAnimation.TopRightY = 0d;
            _BackgroundAnimation.BottomRightY = 420d;
            _BackgroundAnimation.InvisibleBouncePad = 20d;
            _BackgroundAnimation.BounceDamping = 0.97d;
            _BackgroundAnimation.ColorAWeight = 0.7d;
        }
        public void SpringMode()
        {
            _BackgroundAnimation.FillNodes = false;
            _BackgroundAnimation.DrawEdges = false;
            _BackgroundAnimation.BackgroundImageUriLight = "Assets/LoginWindowsBackGround/SpringLight.png";
            _BackgroundAnimation.BackgroundImageUriDark = "Assets/LoginWindowsBackGround/SpringDark.png";
            _BackgroundAnimation.IconScale = 1;
            _BackgroundAnimation.MinNodeRadius = 10;
            _BackgroundAnimation.MaxNodeRadius = 22;
            _BackgroundAnimation.IconMinDiameter = 8;
            _BackgroundAnimation.AppearWidth = 400;
            _BackgroundAnimation.ScrollSpeed = 40;
            _BackgroundAnimation.MaxNodes = 5;
            _BackgroundAnimation.NodeSpawnRate = 5;
            _BackgroundAnimation.NodesOpocity = false;
            _BackgroundAnimation.PulseIconWidth = true;
            _BackgroundAnimation.PulseIconWidthAmplitude = 0.2f;
            _BackgroundAnimation.PulseIconWidthFrequency = 5;
            _BackgroundAnimation.IconUris = GenerateIconUris("Assets/Icons/butterfly", 4, "b.png");

            _BackgroundAnimation.CollisionPadding = 48;
            _BackgroundAnimation.CollisionIterations = 5;
            _BackgroundAnimation.NodeColorA = Color.FromArgb(255, 184, 196, 203);
            _BackgroundAnimation.NodeColorB = Color.FromArgb(255, 246, 208, 100);
            _BackgroundAnimation.TopLeftY = -100d;
            _BackgroundAnimation.BottomLeftY = 240d;
            _BackgroundAnimation.TopRightY = 0d;
            _BackgroundAnimation.BottomRightY = 420d;
            _BackgroundAnimation.InvisibleBouncePad = 20d;
            _BackgroundAnimation.BounceDamping = 0.97d;
            _BackgroundAnimation.ColorAWeight = 0.7d;
        }

        public void SummerMode()
        {
            _BackgroundAnimation.FillNodes = false;
            _BackgroundAnimation.DrawEdges = false;
            _BackgroundAnimation.BackgroundImageUriLight = "Assets/LoginWindowsBackGround/SummerLight.png";
            _BackgroundAnimation.BackgroundImageUriDark = "Assets/LoginWindowsBackGround/SummerDark.png";
            _BackgroundAnimation.IconScale = 1;
            _BackgroundAnimation.MinNodeRadius = 10;
            _BackgroundAnimation.MaxNodeRadius = 22;
            _BackgroundAnimation.IconMinDiameter = 8;
            _BackgroundAnimation.AppearWidth = 400;
            _BackgroundAnimation.ScrollSpeed = 40;
            _BackgroundAnimation.MaxNodes = 5;
            _BackgroundAnimation.NodeSpawnRate = 5;
            _BackgroundAnimation.NodesOpocity = false;
            _BackgroundAnimation.PulseIconWidth = true;
            _BackgroundAnimation.PulseIconWidthAmplitude = 0.2f;
            _BackgroundAnimation.PulseIconWidthFrequency = 5;
            _BackgroundAnimation.IconUris = GenerateIconUris("Assets/Icons/butterfly", 4, "b.png");

            _BackgroundAnimation.CollisionPadding = 48;
            _BackgroundAnimation.CollisionIterations = 5;
            _BackgroundAnimation.NodeColorA = Color.FromArgb(255, 184, 196, 203);
            _BackgroundAnimation.NodeColorB = Color.FromArgb(255, 246, 208, 100);
            _BackgroundAnimation.ColorAWeight = 0.7d;
        }
        public void WinterMode()
        {
            _BackgroundAnimation.FillNodes = false;
            _BackgroundAnimation.DrawEdges = false;
            _BackgroundAnimation.BackgroundImageUriLight = "Assets/LoginWindowsBackGround/WinterLight.png";
            _BackgroundAnimation.BackgroundImageUriDark = "Assets/LoginWindowsBackGround/WinterDark.png";
            _BackgroundAnimation.IconScale = 1;
            _BackgroundAnimation.MinNodeRadius = 8;
            _BackgroundAnimation.MaxNodeRadius = 14;
            _BackgroundAnimation.IconMinDiameter = 8;
            _BackgroundAnimation.AppearWidth = 1400;
            _BackgroundAnimation.ScrollSpeed = 35;
            _BackgroundAnimation.MaxNodes = 25;
            _BackgroundAnimation.NodeSpawnRate = 20;
            _BackgroundAnimation.NodesOpocity = true;
            _BackgroundAnimation.IconUris = GenerateIconUris("Assets/Icons/snowflakes", 5, ".png");

            _BackgroundAnimation.CollisionPadding = 48;
            _BackgroundAnimation.CollisionIterations = 5;
            _BackgroundAnimation.NodeColorA = Color.FromArgb(255, 184, 196, 203);
            _BackgroundAnimation.NodeColorB = Color.FromArgb(255, 246, 208, 100);
            _BackgroundAnimation.ColorAWeight = 0.7d;
        }

        // ===== generator uris (jak miałeś) =====
        public static string GenerateIconUris(string start, int count, string end)
        {
            if (count < 1)
                throw new ArgumentOutOfRangeException(nameof(count));

            var sb = new System.Text.StringBuilder();

            for (int i = 1; i <= count; i++)
            {
                sb.Append($"{start}{i}{end}");
                if (i < count)
                    sb.AppendLine(";");
            }

            return sb.ToString();
        }
    }
}