using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using AxCopilot.Handlers;
using AxCopilot.Models;
using AxCopilot.SDK;
using AxCopilot.Services;
using AxCopilot.ViewModels;
using Microsoft.Win32;

namespace AxCopilot.Views;

public class LauncherWindow : Window, IComponentConnector
{
	[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
	private struct SHFILEOPSTRUCT
	{
		public nint hwnd;

		public uint wFunc;

		[MarshalAs(UnmanagedType.LPWStr)]
		public string pFrom;

		[MarshalAs(UnmanagedType.LPWStr)]
		public string? pTo;

		public ushort fFlags;

		[MarshalAs(UnmanagedType.Bool)]
		public bool fAnyOperationsAborted;

		public nint hNameMappings;

		[MarshalAs(UnmanagedType.LPWStr)]
		public string? lpszProgressTitle;
	}

	private readonly LauncherViewModel _vm;

	private DispatcherTimer? _indexStatusTimer;

	private static readonly Random _iconRng = new Random();

	private Storyboard? _iconStoryboard;

	private DispatcherTimer? _rainbowTimer;

	private static readonly HashSet<string> KnownThemes = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Dark", "Light", "OLED", "Nord", "Monokai", "Catppuccin", "Sepia", "Alfred", "AlfredLight", "Codex" };

	private const uint FO_DELETE = 3u;

	private const ushort FOF_ALLOWUNDO = 64;

	private const ushort FOF_NOCONFIRMATION = 16;

	private const ushort FOF_SILENT = 4;

	private LauncherItem? _lastClickedItem;

	private DateTime _lastClickTime;

	internal Border RainbowGlowBorder;

	internal LinearGradientBrush LauncherRainbowBrush;

	internal Border MainBorder;

	internal Canvas DiamondIcon;

	internal RotateTransform IconRotate;

	internal ScaleTransform IconScale;

	internal Rectangle GlowBlue;

	internal Rectangle GlowGreen1;

	internal Rectangle GlowGreen2;

	internal Rectangle GlowRed;

	internal Rectangle PixelBlue;

	internal Rectangle PixelGreen1;

	internal Rectangle PixelGreen2;

	internal Rectangle PixelRed;

	internal TextBox InputBox;

	internal ListView ResultList;

	internal TextBlock IndexStatusText;

	internal Border ToastOverlay;

	internal TextBlock ToastIcon;

	internal TextBlock ToastText;

	private bool _contentLoaded;

	public Action? OpenSettingsAction { get; set; }

	[DllImport("user32.dll")]
	private static extern bool SetForegroundWindow(nint hWnd);

	[DllImport("user32.dll")]
	private static extern bool ShowWindow(nint hWnd, int nCmdShow);

	[DllImport("user32.dll")]
	private static extern nint GetForegroundWindow();

	[DllImport("user32.dll")]
	private static extern uint GetWindowThreadProcessId(nint hWnd, out uint processId);

	[DllImport("user32.dll")]
	private static extern bool AttachThreadInput(uint idAttach, uint idAttachTo, bool fAttach);

	[DllImport("kernel32.dll")]
	private static extern uint GetCurrentThreadId();

	public LauncherWindow(LauncherViewModel vm)
	{
		_vm = vm;
		ApplyTheme();
		InitializeComponent();
		base.DataContext = vm;
		vm.CloseRequested += delegate
		{
			Hide();
		};
		vm.NotificationRequested += delegate(object? _, string msg)
		{
			ShowNotification(msg);
		};
		vm.PropertyChanged += delegate(object? _, PropertyChangedEventArgs e)
		{
			if (e.PropertyName == "InputText")
			{
				((DispatcherObject)this).Dispatcher.InvokeAsync((Action)delegate
				{
					if (InputBox != null)
					{
						InputBox.CaretIndex = InputBox.Text.Length;
					}
				}, (DispatcherPriority)5);
			}
		};
		App app = (App)Application.Current;
		if (app.IndexService == null)
		{
			return;
		}
		app.IndexService.IndexRebuilt += delegate
		{
			((DispatcherObject)this).Dispatcher.BeginInvoke((Delegate)(Action)delegate
			{
				//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d2: Expected O, but got Unknown
				IndexService indexService = app.IndexService;
				IndexStatusText.Text = $"✓ {indexService.LastIndexCount:N0}개 항목 색인됨 ({indexService.LastIndexDuration.TotalSeconds:F1}초)";
				IndexStatusText.Visibility = Visibility.Visible;
				DispatcherTimer? indexStatusTimer = _indexStatusTimer;
				if (indexStatusTimer != null)
				{
					indexStatusTimer.Stop();
				}
				_indexStatusTimer = new DispatcherTimer
				{
					Interval = TimeSpan.FromSeconds(5.0)
				};
				_indexStatusTimer.Tick += delegate
				{
					IndexStatusText.Visibility = Visibility.Collapsed;
					_indexStatusTimer.Stop();
				};
				_indexStatusTimer.Start();
			}, Array.Empty<object>());
		};
	}

	private void Window_Loaded(object sender, RoutedEventArgs e)
	{
		CenterOnScreen();
		ApplyTheme();
		((DispatcherObject)this).Dispatcher.BeginInvoke((DispatcherPriority)5, (Delegate)(Action)delegate
		{
			Activate();
			ForceForeground();
			InputBox.Focus();
			Keyboard.Focus(InputBox);
		});
	}

	public void SetInputText(string text)
	{
		if (InputBox != null)
		{
			InputBox.Text = text;
			InputBox.CaretIndex = text.Length;
			_vm.InputText = text;
		}
	}

	private void ForceForeground()
	{
		try
		{
			nint handle = new WindowInteropHelper(this).Handle;
			if (handle == IntPtr.Zero)
			{
				return;
			}
			nint foregroundWindow = GetForegroundWindow();
			if (foregroundWindow != handle)
			{
				uint processId;
				uint windowThreadProcessId = GetWindowThreadProcessId(foregroundWindow, out processId);
				uint currentThreadId = GetCurrentThreadId();
				if (windowThreadProcessId != currentThreadId)
				{
					AttachThreadInput(currentThreadId, windowThreadProcessId, fAttach: true);
					SetForegroundWindow(handle);
					AttachThreadInput(currentThreadId, windowThreadProcessId, fAttach: false);
				}
				else
				{
					SetForegroundWindow(handle);
				}
			}
		}
		catch
		{
		}
	}

	public new void Show()
	{
		_vm.RefreshPlaceholder();
		_vm.OnShown();
		_vm.InputText = "";
		base.Show();
		CenterOnScreen();
		AnimateIn();
		Activate();
		ForceForeground();
		((DispatcherObject)this).Dispatcher.BeginInvoke((DispatcherPriority)5, (Delegate)(Action)delegate
		{
			Activate();
			InputBox.Focus();
			Keyboard.Focus(InputBox);
			InputBox.SelectAll();
		});
		((DispatcherObject)this).Dispatcher.BeginInvoke((DispatcherPriority)6, (Delegate)(Action)delegate
		{
			if (!InputBox.IsKeyboardFocused)
			{
				ForceForeground();
				InputBox.Focus();
				Keyboard.Focus(InputBox);
			}
		});
		if (_vm.ShowLauncherBorder)
		{
			MainBorder.BorderThickness = new Thickness(1.0);
			MainBorder.BorderBrush = (Brush)FindResource("BorderColor");
		}
		else
		{
			MainBorder.BorderThickness = new Thickness(0.0);
			MainBorder.BorderBrush = Brushes.Transparent;
		}
		if (_vm.EnableIconAnimation)
		{
			ApplyRandomIconAnimation();
		}
		else
		{
			ResetIconAnimation();
		}
		if (_vm.EnableRainbowGlow)
		{
			StartRainbowGlow();
		}
		else
		{
			StopRainbowGlow();
		}
		UpdateSelectionGlow();
	}

	private void ResetIconAnimation()
	{
		_iconStoryboard?.Stop();
		_iconStoryboard = null;
		Rectangle[] array = new Rectangle[4] { PixelBlue, PixelGreen1, PixelRed, PixelGreen2 };
		Rectangle[] array2 = array;
		foreach (Rectangle rectangle in array2)
		{
			if (rectangle != null)
			{
				rectangle.BeginAnimation(UIElement.OpacityProperty, null);
				rectangle.Opacity = 1.0;
			}
		}
		if (IconRotate != null)
		{
			IconRotate.BeginAnimation(RotateTransform.AngleProperty, null);
			IconRotate.Angle = 45.0;
		}
		if (IconScale != null)
		{
			IconScale.BeginAnimation(ScaleTransform.ScaleXProperty, null);
			IconScale.BeginAnimation(ScaleTransform.ScaleYProperty, null);
			IconScale.ScaleX = 1.0;
			IconScale.ScaleY = 1.0;
		}
	}

	private void ApplyRandomIconAnimation()
	{
		_iconStoryboard?.Stop();
		Rectangle[] array = new Rectangle[4] { PixelBlue, PixelGreen1, PixelRed, PixelGreen2 };
		if (array.Any((Rectangle p) => p == null) || IconRotate == null || IconScale == null)
		{
			return;
		}
		Rectangle[] array2 = array;
		foreach (Rectangle rectangle in array2)
		{
			rectangle.BeginAnimation(UIElement.OpacityProperty, null);
			rectangle.Opacity = 1.0;
		}
		IconRotate.BeginAnimation(RotateTransform.AngleProperty, null);
		IconScale.BeginAnimation(ScaleTransform.ScaleXProperty, null);
		IconScale.BeginAnimation(ScaleTransform.ScaleYProperty, null);
		IconRotate.Angle = 45.0;
		IconScale.ScaleX = 1.0;
		IconScale.ScaleY = 1.0;
		Storyboard storyboard = new Storyboard
		{
			RepeatBehavior = new RepeatBehavior(3.0)
		};
		switch (_iconRng.Next(20))
		{
		case 0:
		{
			for (int num12 = 0; num12 < 4; num12++)
			{
				AddOpacityPulse(storyboard, array[num12], num12, 4.0);
			}
			break;
		}
		case 1:
		{
			Rectangle[] array7 = array;
			foreach (Rectangle value in array7)
			{
				DoubleAnimation doubleAnimation10 = new DoubleAnimation(1.0, 0.35, TimeSpan.FromSeconds(1.5))
				{
					AutoReverse = true
				};
				Storyboard.SetTarget((DependencyObject)(object)doubleAnimation10, (DependencyObject)(object)value);
				Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimation10, new PropertyPath(UIElement.OpacityProperty));
				storyboard.Children.Add(doubleAnimation10);
			}
			break;
		}
		case 2:
		{
			UIElement[] array3 = new Rectangle[2]
			{
				array[0],
				array[3]
			};
			AddGroupFlash(storyboard, array3, 0.0, 3.2);
			array3 = new Rectangle[2]
			{
				array[1],
				array[2]
			};
			AddGroupFlash(storyboard, array3, 1.6, 3.2);
			break;
		}
		case 3:
		{
			Rectangle[] array4 = new Rectangle[4]
			{
				array[0],
				array[1],
				array[3],
				array[2]
			};
			for (int num9 = 0; num9 < 4; num9++)
			{
				DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames11 = MakeKeyFrameAnim(new(double, double)[6]
				{
					(0.15, 0.0),
					(0.15, (double)num9 * 0.5),
					(1.0, (double)num9 * 0.5 + 0.25),
					(1.0, (double)num9 * 0.5 + 0.7),
					(0.15, (double)num9 * 0.5 + 0.95),
					(0.15, 2.5)
				});
				Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames11, (DependencyObject)(object)array4[num9]);
				Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames11, new PropertyPath(UIElement.OpacityProperty));
				storyboard.Children.Add(doubleAnimationUsingKeyFrames11);
			}
			break;
		}
		case 4:
		{
			DoubleAnimation doubleAnimation4 = new DoubleAnimation(45.0, 405.0, TimeSpan.FromSeconds(4.0))
			{
				EasingFunction = new CubicEase
				{
					EasingMode = EasingMode.EaseInOut
				}
			};
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimation4, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimation4, new PropertyPath("RenderTransform.Children[0].Angle"));
			storyboard.Children.Add(doubleAnimation4);
			break;
		}
		case 5:
		{
			DoubleAnimation doubleAnimation2 = new DoubleAnimation(1.0, 1.25, TimeSpan.FromSeconds(0.6))
			{
				AutoReverse = true,
				EasingFunction = new QuadraticEase
				{
					EasingMode = EasingMode.EaseInOut
				}
			};
			DoubleAnimation doubleAnimation3 = new DoubleAnimation(1.0, 1.25, TimeSpan.FromSeconds(0.6))
			{
				AutoReverse = true,
				EasingFunction = new QuadraticEase
				{
					EasingMode = EasingMode.EaseInOut
				}
			};
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimation2, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimation3, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimation2, new PropertyPath("RenderTransform.Children[1].ScaleX"));
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimation3, new PropertyPath("RenderTransform.Children[1].ScaleY"));
			storyboard.Children.Add(doubleAnimation2);
			storyboard.Children.Add(doubleAnimation3);
			break;
		}
		case 6:
		{
			storyboard.RepeatBehavior = RepeatBehavior.Forever;
			DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames4 = new DoubleAnimationUsingKeyFrames();
			doubleAnimationUsingKeyFrames4.KeyFrames.Add(new LinearDoubleKeyFrame(0.7, KT(0.0)));
			doubleAnimationUsingKeyFrames4.KeyFrames.Add(new EasingDoubleKeyFrame(1.15, KT(0.35), new BounceEase
			{
				Bounces = 2,
				Bounciness = 3.0
			}));
			doubleAnimationUsingKeyFrames4.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(0.6)));
			doubleAnimationUsingKeyFrames4.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(3.0)));
			DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames5 = doubleAnimationUsingKeyFrames4.Clone();
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames4, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames5, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames4, new PropertyPath("RenderTransform.Children[1].ScaleX"));
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames5, new PropertyPath("RenderTransform.Children[1].ScaleY"));
			storyboard.Children.Add(doubleAnimationUsingKeyFrames4);
			storyboard.Children.Add(doubleAnimationUsingKeyFrames5);
			break;
		}
		case 7:
		{
			DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames16 = new DoubleAnimationUsingKeyFrames();
			doubleAnimationUsingKeyFrames16.KeyFrames.Add(new LinearDoubleKeyFrame(45.0, KT(0.0)));
			doubleAnimationUsingKeyFrames16.KeyFrames.Add(new LinearDoubleKeyFrame(50.0, KT(0.08)));
			doubleAnimationUsingKeyFrames16.KeyFrames.Add(new LinearDoubleKeyFrame(40.0, KT(0.16)));
			doubleAnimationUsingKeyFrames16.KeyFrames.Add(new LinearDoubleKeyFrame(48.0, KT(0.24)));
			doubleAnimationUsingKeyFrames16.KeyFrames.Add(new LinearDoubleKeyFrame(42.0, KT(0.32)));
			doubleAnimationUsingKeyFrames16.KeyFrames.Add(new LinearDoubleKeyFrame(45.0, KT(0.4)));
			doubleAnimationUsingKeyFrames16.KeyFrames.Add(new LinearDoubleKeyFrame(45.0, KT(3.5)));
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames16, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames16, new PropertyPath("RenderTransform.Children[0].Angle"));
			storyboard.Children.Add(doubleAnimationUsingKeyFrames16);
			break;
		}
		case 8:
		{
			for (int num14 = 0; num14 < 4; num14++)
			{
				DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames15 = new DoubleAnimationUsingKeyFrames();
				double num15 = (double)num14 * 0.3;
				doubleAnimationUsingKeyFrames15.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(0.0)));
				doubleAnimationUsingKeyFrames15.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(num15)));
				doubleAnimationUsingKeyFrames15.KeyFrames.Add(new EasingDoubleKeyFrame(0.1, KT(num15 + 0.25), new QuadraticEase
				{
					EasingMode = EasingMode.EaseOut
				}));
				doubleAnimationUsingKeyFrames15.KeyFrames.Add(new EasingDoubleKeyFrame(1.0, KT(num15 + 0.55), new QuadraticEase
				{
					EasingMode = EasingMode.EaseIn
				}));
				doubleAnimationUsingKeyFrames15.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(3.0)));
				Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames15, (DependencyObject)(object)array[num14]);
				Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames15, new PropertyPath(UIElement.OpacityProperty));
				storyboard.Children.Add(doubleAnimationUsingKeyFrames15);
			}
			break;
		}
		case 9:
		{
			Rectangle[] array6 = array;
			foreach (Rectangle rectangle2 in array6)
			{
				rectangle2.Opacity = 1.0;
			}
			return;
		}
		case 10:
		{
			DoubleAnimation doubleAnimation9 = new DoubleAnimation(45.0, -315.0, TimeSpan.FromSeconds(4.5))
			{
				EasingFunction = new CubicEase
				{
					EasingMode = EasingMode.EaseInOut
				}
			};
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimation9, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimation9, new PropertyPath("RenderTransform.Children[0].Angle"));
			storyboard.Children.Add(doubleAnimation9);
			break;
		}
		case 11:
		{
			DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames13 = new DoubleAnimationUsingKeyFrames();
			doubleAnimationUsingKeyFrames13.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(0.0)));
			doubleAnimationUsingKeyFrames13.KeyFrames.Add(new EasingDoubleKeyFrame(1.3, KT(0.1), new QuadraticEase
			{
				EasingMode = EasingMode.EaseOut
			}));
			doubleAnimationUsingKeyFrames13.KeyFrames.Add(new EasingDoubleKeyFrame(1.0, KT(0.22), new QuadraticEase
			{
				EasingMode = EasingMode.EaseIn
			}));
			doubleAnimationUsingKeyFrames13.KeyFrames.Add(new EasingDoubleKeyFrame(1.2, KT(0.32), new QuadraticEase
			{
				EasingMode = EasingMode.EaseOut
			}));
			doubleAnimationUsingKeyFrames13.KeyFrames.Add(new EasingDoubleKeyFrame(1.0, KT(0.44), new QuadraticEase
			{
				EasingMode = EasingMode.EaseIn
			}));
			doubleAnimationUsingKeyFrames13.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(2.8)));
			DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames14 = doubleAnimationUsingKeyFrames13.Clone();
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames13, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames14, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames13, new PropertyPath("RenderTransform.Children[1].ScaleX"));
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames14, new PropertyPath("RenderTransform.Children[1].ScaleY"));
			storyboard.Children.Add(doubleAnimationUsingKeyFrames13);
			storyboard.Children.Add(doubleAnimationUsingKeyFrames14);
			break;
		}
		case 12:
		{
			double[] array5 = new double[4] { 0.0, 0.5, 1.1, 1.6 };
			for (int num10 = 0; num10 < 4; num10++)
			{
				double num11 = array5[num10];
				DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames12 = new DoubleAnimationUsingKeyFrames();
				doubleAnimationUsingKeyFrames12.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(0.0)));
				doubleAnimationUsingKeyFrames12.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(num11)));
				doubleAnimationUsingKeyFrames12.KeyFrames.Add(new LinearDoubleKeyFrame(0.05, KT(num11 + 0.15)));
				doubleAnimationUsingKeyFrames12.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(num11 + 0.35)));
				doubleAnimationUsingKeyFrames12.KeyFrames.Add(new LinearDoubleKeyFrame(0.5, KT(num11 + 0.5)));
				doubleAnimationUsingKeyFrames12.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(num11 + 0.65)));
				doubleAnimationUsingKeyFrames12.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(3.5)));
				Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames12, (DependencyObject)(object)array[num10]);
				Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames12, new PropertyPath(UIElement.OpacityProperty));
				storyboard.Children.Add(doubleAnimationUsingKeyFrames12);
			}
			break;
		}
		case 13:
		{
			DoubleAnimation doubleAnimation6 = new DoubleAnimation(-135.0, 45.0, TimeSpan.FromSeconds(0.9))
			{
				EasingFunction = new CubicEase
				{
					EasingMode = EasingMode.EaseOut
				}
			};
			DoubleAnimation doubleAnimation7 = new DoubleAnimation(0.4, 1.0, TimeSpan.FromSeconds(0.9))
			{
				EasingFunction = new CubicEase
				{
					EasingMode = EasingMode.EaseOut
				}
			};
			DoubleAnimation doubleAnimation8 = new DoubleAnimation(0.4, 1.0, TimeSpan.FromSeconds(0.9))
			{
				EasingFunction = new CubicEase
				{
					EasingMode = EasingMode.EaseOut
				}
			};
			DoubleAnimation element = new DoubleAnimation(1.0, 1.0, TimeSpan.FromSeconds(2.5))
			{
				BeginTime = TimeSpan.FromSeconds(0.9)
			};
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimation6, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimation7, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimation8, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTarget((DependencyObject)(object)element, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimation6, new PropertyPath("RenderTransform.Children[0].Angle"));
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimation7, new PropertyPath("RenderTransform.Children[1].ScaleX"));
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimation8, new PropertyPath("RenderTransform.Children[1].ScaleY"));
			Storyboard.SetTargetProperty((DependencyObject)(object)element, new PropertyPath("RenderTransform.Children[1].ScaleX"));
			storyboard.Children.Add(doubleAnimation6);
			storyboard.Children.Add(doubleAnimation7);
			storyboard.Children.Add(doubleAnimation8);
			break;
		}
		case 14:
		{
			for (int num7 = 0; num7 < 4; num7++)
			{
				double num8 = (double)num7 * 0.6;
				DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames10 = new DoubleAnimationUsingKeyFrames();
				doubleAnimationUsingKeyFrames10.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(0.0)));
				doubleAnimationUsingKeyFrames10.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(num8)));
				doubleAnimationUsingKeyFrames10.KeyFrames.Add(new EasingDoubleKeyFrame(0.0, KT(num8 + 0.3), new QuadraticEase
				{
					EasingMode = EasingMode.EaseIn
				}));
				doubleAnimationUsingKeyFrames10.KeyFrames.Add(new EasingDoubleKeyFrame(1.0, KT(num8 + 0.6), new QuadraticEase
				{
					EasingMode = EasingMode.EaseOut
				}));
				doubleAnimationUsingKeyFrames10.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(3.5)));
				Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames10, (DependencyObject)(object)array[num7]);
				Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames10, new PropertyPath(UIElement.OpacityProperty));
				storyboard.Children.Add(doubleAnimationUsingKeyFrames10);
			}
			break;
		}
		case 15:
		{
			DoubleAnimation doubleAnimation5 = new DoubleAnimation(45.0, 405.0, TimeSpan.FromSeconds(2.0))
			{
				EasingFunction = new BackEase
				{
					EasingMode = EasingMode.EaseInOut,
					Amplitude = 0.3
				}
			};
			DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames8 = new DoubleAnimationUsingKeyFrames();
			doubleAnimationUsingKeyFrames8.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(0.0)));
			doubleAnimationUsingKeyFrames8.KeyFrames.Add(new EasingDoubleKeyFrame(1.4, KT(1.0), new QuadraticEase
			{
				EasingMode = EasingMode.EaseOut
			}));
			doubleAnimationUsingKeyFrames8.KeyFrames.Add(new EasingDoubleKeyFrame(1.0, KT(2.0), new QuadraticEase
			{
				EasingMode = EasingMode.EaseIn
			}));
			doubleAnimationUsingKeyFrames8.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(3.5)));
			DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames9 = doubleAnimationUsingKeyFrames8.Clone();
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimation5, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames8, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames9, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimation5, new PropertyPath("RenderTransform.Children[0].Angle"));
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames8, new PropertyPath("RenderTransform.Children[1].ScaleX"));
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames9, new PropertyPath("RenderTransform.Children[1].ScaleY"));
			storyboard.Children.Add(doubleAnimation5);
			storyboard.Children.Add(doubleAnimationUsingKeyFrames8);
			storyboard.Children.Add(doubleAnimationUsingKeyFrames9);
			break;
		}
		case 16:
		{
			for (int num5 = 0; num5 < 4; num5++)
			{
				double num6 = (double)num5 * 0.15;
				DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames7 = new DoubleAnimationUsingKeyFrames();
				doubleAnimationUsingKeyFrames7.KeyFrames.Add(new LinearDoubleKeyFrame(0.0, KT(0.0)));
				doubleAnimationUsingKeyFrames7.KeyFrames.Add(new LinearDoubleKeyFrame(0.0, KT(num6)));
				doubleAnimationUsingKeyFrames7.KeyFrames.Add(new EasingDoubleKeyFrame(1.0, KT(num6 + 0.5), new BounceEase
				{
					Bounces = 3,
					Bounciness = 2.5
				}));
				doubleAnimationUsingKeyFrames7.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(3.0)));
				Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames7, (DependencyObject)(object)array[num5]);
				Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames7, new PropertyPath(UIElement.OpacityProperty));
				storyboard.Children.Add(doubleAnimationUsingKeyFrames7);
			}
			break;
		}
		case 17:
		{
			DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames6 = new DoubleAnimationUsingKeyFrames();
			doubleAnimationUsingKeyFrames6.KeyFrames.Add(new LinearDoubleKeyFrame(45.0, KT(0.0)));
			doubleAnimationUsingKeyFrames6.KeyFrames.Add(new EasingDoubleKeyFrame(60.0, KT(0.3), new SineEase
			{
				EasingMode = EasingMode.EaseOut
			}));
			doubleAnimationUsingKeyFrames6.KeyFrames.Add(new EasingDoubleKeyFrame(30.0, KT(0.9), new SineEase
			{
				EasingMode = EasingMode.EaseInOut
			}));
			doubleAnimationUsingKeyFrames6.KeyFrames.Add(new EasingDoubleKeyFrame(55.0, KT(1.5), new SineEase
			{
				EasingMode = EasingMode.EaseInOut
			}));
			doubleAnimationUsingKeyFrames6.KeyFrames.Add(new EasingDoubleKeyFrame(38.0, KT(2.1), new SineEase
			{
				EasingMode = EasingMode.EaseInOut
			}));
			doubleAnimationUsingKeyFrames6.KeyFrames.Add(new EasingDoubleKeyFrame(45.0, KT(2.5), new SineEase
			{
				EasingMode = EasingMode.EaseIn
			}));
			doubleAnimationUsingKeyFrames6.KeyFrames.Add(new LinearDoubleKeyFrame(45.0, KT(4.0)));
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames6, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames6, new PropertyPath("RenderTransform.Children[0].Angle"));
			storyboard.Children.Add(doubleAnimationUsingKeyFrames6);
			break;
		}
		case 18:
		{
			for (int num2 = 0; num2 < 4; num2++)
			{
				DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
				double num3 = (double)num2 * 0.08;
				doubleAnimationUsingKeyFrames.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(0.0)));
				for (int num4 = 0; num4 < 6; num4++)
				{
					double sec = num3 + (double)num4 * 0.12;
					doubleAnimationUsingKeyFrames.KeyFrames.Add(new LinearDoubleKeyFrame((num4 % 2 == 0) ? 0.1 : 1.0, KT(sec)));
				}
				doubleAnimationUsingKeyFrames.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(1.2)));
				doubleAnimationUsingKeyFrames.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(3.5)));
				Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames, (DependencyObject)(object)array[num2]);
				Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames, new PropertyPath(UIElement.OpacityProperty));
				storyboard.Children.Add(doubleAnimationUsingKeyFrames);
			}
			DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames2 = new DoubleAnimationUsingKeyFrames();
			doubleAnimationUsingKeyFrames2.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(0.0)));
			doubleAnimationUsingKeyFrames2.KeyFrames.Add(new EasingDoubleKeyFrame(1.5, KT(0.15), new QuadraticEase
			{
				EasingMode = EasingMode.EaseOut
			}));
			doubleAnimationUsingKeyFrames2.KeyFrames.Add(new EasingDoubleKeyFrame(0.8, KT(0.4), new ElasticEase
			{
				Oscillations = 2,
				Springiness = 5.0
			}));
			doubleAnimationUsingKeyFrames2.KeyFrames.Add(new EasingDoubleKeyFrame(1.0, KT(0.7), new QuadraticEase
			{
				EasingMode = EasingMode.EaseOut
			}));
			doubleAnimationUsingKeyFrames2.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(3.5)));
			DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames3 = doubleAnimationUsingKeyFrames2.Clone();
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames2, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames3, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames2, new PropertyPath("RenderTransform.Children[1].ScaleX"));
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames3, new PropertyPath("RenderTransform.Children[1].ScaleY"));
			storyboard.Children.Add(doubleAnimationUsingKeyFrames2);
			storyboard.Children.Add(doubleAnimationUsingKeyFrames3);
			break;
		}
		case 19:
		{
			UIElement[] array3 = new Rectangle[2]
			{
				array[0],
				array[3]
			};
			AddGroupFlash(storyboard, array3, 0.0, 4.0);
			array3 = new Rectangle[2]
			{
				array[1],
				array[2]
			};
			AddGroupFlash(storyboard, array3, 0.8, 4.0);
			DoubleAnimation doubleAnimation = new DoubleAnimation(45.0, 225.0, TimeSpan.FromSeconds(4.0))
			{
				EasingFunction = new SineEase
				{
					EasingMode = EasingMode.EaseInOut
				}
			};
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimation, (DependencyObject)(object)DiamondIcon);
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimation, new PropertyPath("RenderTransform.Children[0].Angle"));
			storyboard.Children.Add(doubleAnimation);
			break;
		}
		}
		_iconStoryboard = storyboard;
		storyboard.Completed += delegate
		{
			if (_vm.EnableIconAnimation && base.IsVisible)
			{
				ApplyRandomIconAnimation();
			}
		};
		storyboard.Begin(this, isControllable: true);
	}

	private void DiamondIcon_Click(object sender, MouseButtonEventArgs e)
	{
		if (_vm.EnableIconAnimation)
		{
			ApplyRandomIconAnimation();
		}
	}

	private void UpdateSelectionGlow()
	{
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		if (_vm.EnableSelectionGlow)
		{
			GradientStopCollection gradientStopCollection = new GradientStopCollection
			{
				new GradientStop(Color.FromRgb(byte.MaxValue, 107, 107), 0.0),
				new GradientStop(Color.FromRgb(254, 202, 87), 0.17),
				new GradientStop(Color.FromRgb(72, 219, 251), 0.33),
				new GradientStop(Color.FromRgb(byte.MaxValue, 159, 243), 0.5),
				new GradientStop(Color.FromRgb(84, 160, byte.MaxValue), 0.67),
				new GradientStop(Color.FromRgb(95, 39, 205), 0.83),
				new GradientStop(Color.FromRgb(byte.MaxValue, 107, 107), 1.0)
			};
			base.Resources["SelectionGlowBrush"] = new LinearGradientBrush(gradientStopCollection, new Point(0.0, 0.0), new Point(1.0, 1.0));
			base.Resources["SelectionGlowVisibility"] = Visibility.Visible;
		}
		else
		{
			base.Resources["SelectionGlowBrush"] = Brushes.Transparent;
			base.Resources["SelectionGlowVisibility"] = Visibility.Collapsed;
		}
	}

	private void StopRainbowGlow()
	{
		DispatcherTimer? rainbowTimer = _rainbowTimer;
		if (rainbowTimer != null)
		{
			rainbowTimer.Stop();
		}
		_rainbowTimer = null;
		if (RainbowGlowBorder != null)
		{
			RainbowGlowBorder.Opacity = 0.0;
		}
	}

	private void StartRainbowGlow()
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		DispatcherTimer? rainbowTimer = _rainbowTimer;
		if (rainbowTimer != null)
		{
			rainbowTimer.Stop();
		}
		if (LauncherRainbowBrush == null || RainbowGlowBorder == null)
		{
			return;
		}
		_rainbowTimer = new DispatcherTimer
		{
			Interval = TimeSpan.FromMilliseconds(20.0)
		};
		DateTime startTime = DateTime.UtcNow;
		_rainbowTimer.Tick += delegate
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			if (!base.IsVisible)
			{
				DispatcherTimer? rainbowTimer2 = _rainbowTimer;
				if (rainbowTimer2 != null)
				{
					rainbowTimer2.Stop();
				}
			}
			else
			{
				double totalMilliseconds = (DateTime.UtcNow - startTime).TotalMilliseconds;
				double num = totalMilliseconds / 2000.0 % 1.0;
				double num2 = num * Math.PI * 2.0;
				LauncherRainbowBrush.StartPoint = new Point(0.5 + 0.5 * Math.Cos(num2), 0.5 + 0.5 * Math.Sin(num2));
				LauncherRainbowBrush.EndPoint = new Point(0.5 - 0.5 * Math.Cos(num2), 0.5 - 0.5 * Math.Sin(num2));
			}
		};
		_rainbowTimer.Start();
	}

	private static KeyTime KT(double sec)
	{
		return KeyTime.FromTimeSpan(TimeSpan.FromSeconds(sec));
	}

	private static void AddOpacityPulse(Storyboard sb, UIElement target, int index, double totalSec)
	{
		DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
		doubleAnimationUsingKeyFrames.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(index)));
		doubleAnimationUsingKeyFrames.KeyFrames.Add(new LinearDoubleKeyFrame(0.25, KT((double)index + 0.5)));
		doubleAnimationUsingKeyFrames.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(index + 1)));
		doubleAnimationUsingKeyFrames.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(totalSec)));
		Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames, (DependencyObject)(object)target);
		Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames, new PropertyPath(UIElement.OpacityProperty));
		sb.Children.Add(doubleAnimationUsingKeyFrames);
	}

	private static void AddGroupFlash(Storyboard sb, UIElement[] group, double startSec, double totalSec)
	{
		foreach (UIElement value in group)
		{
			DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
			doubleAnimationUsingKeyFrames.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(0.0)));
			doubleAnimationUsingKeyFrames.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(startSec)));
			doubleAnimationUsingKeyFrames.KeyFrames.Add(new LinearDoubleKeyFrame(0.2, KT(startSec + 0.6)));
			doubleAnimationUsingKeyFrames.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(startSec + 1.2)));
			doubleAnimationUsingKeyFrames.KeyFrames.Add(new LinearDoubleKeyFrame(1.0, KT(totalSec)));
			Storyboard.SetTarget((DependencyObject)(object)doubleAnimationUsingKeyFrames, (DependencyObject)(object)value);
			Storyboard.SetTargetProperty((DependencyObject)(object)doubleAnimationUsingKeyFrames, new PropertyPath(UIElement.OpacityProperty));
			sb.Children.Add(doubleAnimationUsingKeyFrames);
		}
	}

	private static DoubleAnimationUsingKeyFrames MakeKeyFrameAnim((double val, double sec)[] frames)
	{
		DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
		for (int i = 0; i < frames.Length; i++)
		{
			var (value, sec) = frames[i];
			doubleAnimationUsingKeyFrames.KeyFrames.Add(new LinearDoubleKeyFrame(value, KT(sec)));
		}
		return doubleAnimationUsingKeyFrames;
	}

	private void CenterOnScreen()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		Rect workArea = SystemParameters.WorkArea;
		double num = ((base.ActualWidth > 0.0) ? base.ActualWidth : 640.0);
		double num2 = ((base.ActualHeight > 0.0) ? base.ActualHeight : 80.0);
		base.Left = (((Rect)(ref workArea)).Width - num) / 2.0 + ((Rect)(ref workArea)).Left;
		string windowPosition = _vm.WindowPosition;
		if (1 == 0)
		{
		}
		double top = ((windowPosition == "center") ? ((((Rect)(ref workArea)).Height - num2) / 2.0 + ((Rect)(ref workArea)).Top) : ((!(windowPosition == "bottom")) ? (((Rect)(ref workArea)).Height * 0.2 + ((Rect)(ref workArea)).Top) : (((Rect)(ref workArea)).Height * 0.75 + ((Rect)(ref workArea)).Top)));
		if (1 == 0)
		{
		}
		base.Top = top;
	}

	internal void ApplyTheme()
	{
		ApplyTheme(_vm.ThemeSetting, _vm.CustomThemeColors);
	}

	internal void ApplyTheme(string? themeKey, CustomThemeColors? customColors)
	{
		Collection<ResourceDictionary> mergedDictionaries = Application.Current.Resources.MergedDictionaries;
		ResourceDictionary resourceDictionary = mergedDictionaries.FirstOrDefault(delegate(ResourceDictionary d)
		{
			Uri source = d.Source;
			return ((object)source != null && source.ToString().Contains("/Themes/")) || d.Contains("LauncherBackground");
		});
		if (resourceDictionary != null)
		{
			mergedDictionaries.Remove(resourceDictionary);
		}
		string text = (themeKey ?? "system").ToLowerInvariant();
		if (text == "custom" && customColors != null)
		{
			mergedDictionaries.Add(BuildCustomDictionary(customColors));
			UpdateSelectionGlow();
			return;
		}
		string effectiveThemeName = GetEffectiveThemeName(text);
		mergedDictionaries.Add(new ResourceDictionary
		{
			Source = new Uri("pack://application:,,,/Themes/" + effectiveThemeName + ".xaml")
		});
		UpdateSelectionGlow();
	}

	private static string GetEffectiveThemeName(string setting)
	{
		if (1 == 0)
		{
		}
		string result = setting switch
		{
			"dark" => "Dark", 
			"light" => "Light", 
			"oled" => "OLED", 
			"nord" => "Nord", 
			"monokai" => "Monokai", 
			"catppuccin" => "Catppuccin", 
			"sepia" => "Sepia", 
			"alfred" => "Alfred", 
			"alfredlight" => "AlfredLight", 
			"codex" => "Codex", 
			_ => IsSystemDarkMode() ? "Dark" : "Light", 
		};
		if (1 == 0)
		{
		}
		return result;
	}

	private static ResourceDictionary BuildCustomDictionary(CustomThemeColors c)
	{
		return new ResourceDictionary
		{
			{
				"LauncherBackground",
				Brush(c.LauncherBackground)
			},
			{
				"ItemBackground",
				Brush(c.ItemBackground)
			},
			{
				"ItemSelectedBackground",
				Brush(c.ItemSelectedBackground)
			},
			{
				"ItemSelectedHoverBackground",
				LightenBrush(Brush(c.ItemSelectedBackground), 0.15)
			},
			{
				"ItemHoverBackground",
				Brush(c.ItemHoverBackground)
			},
			{
				"PrimaryText",
				Brush(c.PrimaryText)
			},
			{
				"SecondaryText",
				Brush(c.SecondaryText)
			},
			{
				"PlaceholderText",
				Brush(c.PlaceholderText)
			},
			{
				"AccentColor",
				Brush(c.AccentColor)
			},
			{
				"SeparatorColor",
				Brush(c.SeparatorColor)
			},
			{
				"HintBackground",
				Brush(c.HintBackground)
			},
			{
				"HintText",
				Brush(c.HintText)
			},
			{
				"BorderColor",
				Brush(c.BorderColor)
			},
			{
				"ScrollbarThumb",
				Brush(c.ScrollbarThumb)
			},
			{
				"ShadowColor",
				(Color)ColorConverter.ConvertFromString(c.ShadowColor)
			},
			{
				"WindowCornerRadius",
				new CornerRadius(Math.Clamp(c.WindowCornerRadius, 0, 30))
			},
			{
				"ItemCornerRadius",
				new CornerRadius(Math.Clamp(c.ItemCornerRadius, 0, 20))
			}
		};
		static SolidColorBrush Brush(string hex)
		{
			Color color = (Color)ColorConverter.ConvertFromString(hex);
			return new SolidColorBrush(color);
		}
	}

	private static SolidColorBrush LightenBrush(SolidColorBrush brush, double amount)
	{
		Color color = brush.Color;
		return new SolidColorBrush(Color.FromRgb(Clamp(color.R + (int)(255.0 * amount)), Clamp(color.G + (int)(255.0 * amount)), Clamp(color.B + (int)(255.0 * amount))));
		static byte Clamp(int v)
		{
			return (byte)Math.Min(255, Math.Max(0, v));
		}
	}

	private static bool IsSystemDarkMode()
	{
		try
		{
			using RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");
			return registryKey?.GetValue("AppsUseLightTheme") is int num && num == 0;
		}
		catch
		{
			return true;
		}
	}

	private void AnimateIn()
	{
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		base.Opacity = 0.0;
		CubicEase easingFunction = new CubicEase
		{
			EasingMode = EasingMode.EaseOut
		};
		DoubleAnimation animation = new DoubleAnimation(0.0, 1.0, TimeSpan.FromMilliseconds(100.0))
		{
			EasingFunction = easingFunction
		};
		DoubleAnimation animation2 = new DoubleAnimation(-8.0, 0.0, TimeSpan.FromMilliseconds(120.0))
		{
			EasingFunction = easingFunction
		};
		BeginAnimation(UIElement.OpacityProperty, animation);
		if (base.Content is FrameworkElement frameworkElement)
		{
			TranslateTransform translateTransform = (TranslateTransform)(frameworkElement.RenderTransform = new TranslateTransform(0.0, -10.0));
			frameworkElement.RenderTransformOrigin = new Point(0.5, 0.0);
			translateTransform.BeginAnimation(TranslateTransform.YProperty, animation2);
		}
	}

	private void InputBox_TextChanged(object sender, TextChangedEventArgs e)
	{
		if (!(_vm.InputText == InputBox.Text))
		{
			_vm.TriggerImeSearchAsync(InputBox.Text);
		}
	}

	private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Invalid comparison between Unknown and I4
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Invalid comparison between Unknown and I4
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Invalid comparison between Unknown and I4
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Invalid comparison between Unknown and I4
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Expected I4, but got Unknown
		bool flag = (Keyboard.Modifiers & 4) > 0;
		Key key = e.Key;
		Key val = key;
		if ((int)val != 3)
		{
			if ((int)val != 6)
			{
				switch (val - 13)
				{
				case 0:
					if (_vm.IsActionMode)
					{
						_vm.ExitActionMode();
					}
					else
					{
						Hide();
					}
					e.Handled = true;
					break;
				case 13:
					if (flag)
					{
						_vm.ToggleMergeItem(_vm.SelectedItem);
						_vm.SelectNext();
					}
					else
					{
						_vm.SelectNext();
					}
					ScrollToSelected();
					e.Handled = true;
					break;
				case 11:
					if (flag)
					{
						_vm.ToggleMergeItem(_vm.SelectedItem);
						_vm.SelectPrev();
					}
					else
					{
						_vm.SelectPrev();
					}
					ScrollToSelected();
					e.Handled = true;
					break;
				case 12:
					if (InputBox.CaretIndex == InputBox.Text.Length && InputBox.Text.Length > 0 && _vm.CanEnterActionMode())
					{
						_vm.EnterActionMode(_vm.SelectedItem);
						e.Handled = true;
					}
					break;
				case 7:
				{
					for (int i = 0; i < 5; i++)
					{
						if (_vm.Results.Count <= 0)
						{
							break;
						}
						_vm.SelectNext();
					}
					ScrollToSelected();
					e.Handled = true;
					break;
				}
				case 6:
				{
					for (int j = 0; j < 5; j++)
					{
						if (_vm.Results.Count <= 0)
						{
							break;
						}
						_vm.SelectPrev();
					}
					ScrollToSelected();
					e.Handled = true;
					break;
				}
				case 9:
					if (InputBox.CaretIndex == 0 || string.IsNullOrEmpty(InputBox.Text))
					{
						_vm.SelectFirst();
						ScrollToSelected();
						e.Handled = true;
					}
					break;
				case 8:
					if (InputBox.CaretIndex == InputBox.Text.Length || string.IsNullOrEmpty(InputBox.Text))
					{
						_vm.SelectLast();
						ScrollToSelected();
						e.Handled = true;
					}
					break;
				case 1:
				case 2:
				case 3:
				case 4:
				case 5:
				case 10:
					break;
				}
			}
			else
			{
				if ((Keyboard.Modifiers & 2) != 0 || (Keyboard.Modifiers & 1) > 0)
				{
					return;
				}
				if (flag)
				{
					object obj = _vm.SelectedItem?.Data;
					IndexEntry shiftEntry = obj as IndexEntry;
					if (shiftEntry != null)
					{
						string expanded = Environment.ExpandEnvironmentVariables(shiftEntry.Path);
						Hide();
						Task.Run(delegate
						{
							try
							{
								if (shiftEntry.Type == IndexEntryType.Folder)
								{
									Process.Start("explorer.exe", "\"" + expanded + "\"");
								}
								else
								{
									Process.Start("explorer.exe", "/select,\"" + expanded + "\"");
								}
							}
							catch
							{
							}
						});
					}
					else if (_vm.ActivePrefix == null || !_vm.ActivePrefix.Equals("cap", StringComparison.OrdinalIgnoreCase) || !_vm.ShowDelayTimerItems())
					{
						if (_vm.MergeCount > 0)
						{
							_vm.ExecuteMerge();
						}
						else
						{
							ShowLargeType();
						}
					}
				}
				else if (!_vm.IsActionMode || !TryHandleSpecialAction())
				{
					_vm.ExecuteSelectedAsync();
				}
				e.Handled = true;
			}
			return;
		}
		if (_vm.SelectedItem != null)
		{
			_vm.InputText = _vm.SelectedItem.Title;
			((DispatcherObject)this).Dispatcher.BeginInvoke((Delegate)(Action)delegate
			{
				InputBox.CaretIndex = InputBox.Text.Length;
				InputBox.Focus();
			}, (DispatcherPriority)5, Array.Empty<object>());
		}
		e.Handled = true;
	}

	private void Window_KeyDown(object sender, KeyEventArgs e)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Invalid comparison between Unknown and I4
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Invalid comparison between Unknown and I4
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Invalid comparison between Unknown and I4
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Invalid comparison between Unknown and I4
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Invalid comparison between Unknown and I4
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Invalid comparison between Unknown and I4
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Invalid comparison between Unknown and I4
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Invalid comparison between Unknown and I4
		//IL_027d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Invalid comparison between Unknown and I4
		//IL_0286: Unknown result type (might be due to invalid IL or missing references)
		//IL_0288: Invalid comparison between Unknown and I4
		//IL_02de: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e5: Invalid comparison between Unknown and I4
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e9: Invalid comparison between Unknown and I4
		//IL_0325: Unknown result type (might be due to invalid IL or missing references)
		//IL_032c: Invalid comparison between Unknown and I4
		//IL_032e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0330: Invalid comparison between Unknown and I4
		//IL_0362: Unknown result type (might be due to invalid IL or missing references)
		//IL_0368: Invalid comparison between Unknown and I4
		//IL_036a: Unknown result type (might be due to invalid IL or missing references)
		//IL_036c: Invalid comparison between Unknown and I4
		//IL_039e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a4: Invalid comparison between Unknown and I4
		//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a8: Invalid comparison between Unknown and I4
		//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d5: Invalid comparison between Unknown and I4
		//IL_03d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d9: Invalid comparison between Unknown and I4
		//IL_0422: Unknown result type (might be due to invalid IL or missing references)
		//IL_0429: Invalid comparison between Unknown and I4
		//IL_042b: Unknown result type (might be due to invalid IL or missing references)
		//IL_042d: Invalid comparison between Unknown and I4
		//IL_0476: Unknown result type (might be due to invalid IL or missing references)
		//IL_047d: Invalid comparison between Unknown and I4
		//IL_047f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0481: Invalid comparison between Unknown and I4
		//IL_04f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0500: Invalid comparison between Unknown and I4
		//IL_0502: Unknown result type (might be due to invalid IL or missing references)
		//IL_0504: Invalid comparison between Unknown and I4
		//IL_0535: Unknown result type (might be due to invalid IL or missing references)
		//IL_053c: Invalid comparison between Unknown and I4
		//IL_053e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0540: Invalid comparison between Unknown and I4
		//IL_056d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0574: Invalid comparison between Unknown and I4
		//IL_0576: Unknown result type (might be due to invalid IL or missing references)
		//IL_0578: Invalid comparison between Unknown and I4
		//IL_05bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c3: Invalid comparison between Unknown and I4
		//IL_05c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c7: Invalid comparison between Unknown and I4
		//IL_06f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_06fb: Invalid comparison between Unknown and I4
		//IL_06fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ff: Invalid comparison between Unknown and I4
		//IL_0743: Unknown result type (might be due to invalid IL or missing references)
		//IL_074a: Invalid comparison between Unknown and I4
		//IL_074c: Unknown result type (might be due to invalid IL or missing references)
		//IL_074e: Invalid comparison between Unknown and I4
		//IL_076f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0776: Invalid comparison between Unknown and I4
		//IL_07fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_07fd: Invalid comparison between Unknown and I4
		//IL_080a: Unknown result type (might be due to invalid IL or missing references)
		//IL_080f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0815: Unknown result type (might be due to invalid IL or missing references)
		//IL_0819: Unknown result type (might be due to invalid IL or missing references)
		//IL_0843: Expected I4, but got Unknown
		ModifierKeys modifiers = Keyboard.Modifiers;
		if ((int)e.Key == 142 && (int)modifiers == 2)
		{
			Hide();
			OpenSettingsAction?.Invoke();
			e.Handled = true;
		}
		else if ((int)e.Key == 90)
		{
			_vm.InputText = "help";
			e.Handled = true;
		}
		else if ((int)e.Key == 94)
		{
			App app = (App)Application.Current;
			app.IndexService?.BuildAsync(CancellationToken.None);
			IndexStatusText.Text = "⟳ 인덱스 재구축 중…";
			IndexStatusText.Visibility = Visibility.Visible;
			e.Handled = true;
		}
		else if ((int)e.Key == 32 && (int)modifiers == 0)
		{
			if (_vm.SelectedItem != null)
			{
				string text = _vm.InputText ?? "";
				if (text.StartsWith("note", StringComparison.OrdinalIgnoreCase) && _vm.SelectedItem.Data is string text2 && text2 != "__CLEAR__")
				{
					string title = _vm.SelectedItem.Title;
					MessageBoxResult messageBoxResult = CustomMessageBox.Show("'" + title + "' 메모를 삭제하시겠습니까?", "AX Copilot", MessageBoxButton.OKCancel, MessageBoxImage.Question);
					if (messageBoxResult == MessageBoxResult.OK)
					{
						NoteHandler.DeleteNote(text2);
						string text3 = _vm.InputText ?? "";
						_vm.InputText = text3 + " ";
						_vm.InputText = text3;
					}
				}
				else
				{
					string title2 = _vm.SelectedItem.Title;
					MessageBoxResult messageBoxResult2 = CustomMessageBox.Show("'" + title2 + "' 항목을 목록에서 제거하시겠습니까?", "AX Copilot", MessageBoxButton.OKCancel, MessageBoxImage.Question);
					if (messageBoxResult2 == MessageBoxResult.OK)
					{
						_vm.RemoveSelectedFromRecent();
					}
				}
			}
			e.Handled = true;
		}
		else if ((int)e.Key == 55 && (int)modifiers == 2)
		{
			_vm.ClearInput();
			InputBox.Focus();
			e.Handled = true;
		}
		else if ((int)e.Key == 46 && (int)modifiers == 2 && _vm.SelectedItem?.Data is IndexEntry)
		{
			_vm.CopySelectedPath();
			ShowToast("이름 복사됨");
			e.Handled = true;
		}
		else if ((int)e.Key == 46 && (int)modifiers == 6)
		{
			if (_vm.CopySelectedFullPath())
			{
				ShowToast("경로 복사됨");
			}
			e.Handled = true;
		}
		else if ((int)e.Key == 48 && (int)modifiers == 6)
		{
			if (_vm.OpenSelectedInExplorer())
			{
				Hide();
			}
			e.Handled = true;
		}
		else if ((int)e.Key == 6 && (int)modifiers == 2)
		{
			if (_vm.RunSelectedAsAdmin())
			{
				Hide();
			}
			e.Handled = true;
		}
		else if ((int)e.Key == 6 && (int)modifiers == 1)
		{
			_vm.ShowSelectedProperties();
			e.Handled = true;
		}
		else if ((int)e.Key == 51 && (int)modifiers == 2)
		{
			_vm.InputText = "#";
			((DispatcherObject)this).Dispatcher.BeginInvoke((Delegate)(Action)delegate
			{
				InputBox.CaretIndex = InputBox.Text.Length;
			}, (DispatcherPriority)5, Array.Empty<object>());
			e.Handled = true;
		}
		else if ((int)e.Key == 61 && (int)modifiers == 2)
		{
			_vm.InputText = "recent";
			((DispatcherObject)this).Dispatcher.BeginInvoke((Delegate)(Action)delegate
			{
				InputBox.CaretIndex = InputBox.Text.Length;
			}, (DispatcherPriority)5, Array.Empty<object>());
			e.Handled = true;
		}
		else if ((int)e.Key == 45 && (int)modifiers == 2)
		{
			if (_vm.InputText.TrimStart().Equals("fav", StringComparison.OrdinalIgnoreCase))
			{
				_vm.ClearInput();
			}
			else
			{
				_vm.InputText = "fav";
			}
			((DispatcherObject)this).Dispatcher.BeginInvoke((Delegate)(Action)delegate
			{
				InputBox.CaretIndex = InputBox.Text.Length;
			}, (DispatcherPriority)5, Array.Empty<object>());
			e.Handled = true;
		}
		else if ((int)e.Key == 54 && (int)modifiers == 2)
		{
			ShortcutHelpWindow shortcutHelpWindow = new ShortcutHelpWindow
			{
				Owner = this
			};
			shortcutHelpWindow.ShowDialog();
			e.Handled = true;
		}
		else if ((int)e.Key == 63 && (int)modifiers == 2)
		{
			_vm.OpenSelectedInTerminal();
			Hide();
			e.Handled = true;
		}
		else if ((int)e.Key == 49 && (int)modifiers == 2)
		{
			_vm.ClearInput();
			((DispatcherObject)this).Dispatcher.BeginInvoke((Delegate)(Action)delegate
			{
				InputBox.Focus();
				InputBox.CaretIndex = InputBox.Text.Length;
			}, (DispatcherPriority)5, Array.Empty<object>());
			e.Handled = true;
		}
		else if ((int)e.Key == 59 && (int)modifiers == 2)
		{
			if (_vm.IsClipboardMode && _vm.SelectedItem?.Data is ClipboardEntry clipboardEntry)
			{
				((Application.Current as App)?.ClipboardHistoryService)?.TogglePin(clipboardEntry);
				ShowToast(clipboardEntry.IsPinned ? "클립보드 핀 고정 \ud83d\udccc" : "클립보드 핀 해제");
				_vm.InputText = _vm.InputText;
			}
			else
			{
				bool? flag = _vm.ToggleFavorite();
				if (flag == true)
				{
					ShowToast("즐겨찾기에 추가됨  ⭐");
				}
				else if (flag == false)
				{
					ShowToast("즐겨찾기에서 제거됨");
				}
				else
				{
					ShowToast("파일/폴더 항목을 선택하세요");
				}
			}
			e.Handled = true;
		}
		else if ((int)e.Key == 47 && (int)modifiers == 2)
		{
			_vm.NavigateToDownloads();
			((DispatcherObject)this).Dispatcher.BeginInvoke((Delegate)(Action)delegate
			{
				InputBox.CaretIndex = InputBox.Text.Length;
			}, (DispatcherPriority)5, Array.Empty<object>());
			e.Handled = true;
		}
		else if ((int)e.Key == 66 && (int)modifiers == 2)
		{
			Hide();
			e.Handled = true;
		}
		else if ((int)e.Key == 91)
		{
			if (_vm.SelectedItem?.Data is IndexEntry indexEntry)
			{
				string text4 = Environment.ExpandEnvironmentVariables(indexEntry.Path);
				_vm.InputText = "rename " + text4;
				((DispatcherObject)this).Dispatcher.BeginInvoke((Delegate)(Action)delegate
				{
					InputBox.CaretIndex = InputBox.Text.Length;
				}, (DispatcherPriority)5, Array.Empty<object>());
			}
			e.Handled = true;
		}
		else if ((int)modifiers == 2)
		{
			Key key = e.Key;
			if (1 == 0)
			{
			}
			int num = (key - 35) switch
			{
				0 => 1, 
				1 => 2, 
				2 => 3, 
				3 => 4, 
				4 => 5, 
				5 => 6, 
				6 => 7, 
				7 => 8, 
				8 => 9, 
				_ => 0, 
			};
			if (1 == 0)
			{
			}
			int num2 = num;
			if (num2 > 0 && num2 <= _vm.Results.Count)
			{
				_vm.SelectedItem = _vm.Results[num2 - 1];
				_vm.ExecuteSelectedAsync();
				Hide();
				e.Handled = true;
			}
		}
	}

	private void ShowShortcutHelp()
	{
		string[] value = new string[28]
		{
			"[ 전역 ]", "Alt+Space      AX Commander 열기/닫기", "", "[ 탐색 ]", "↑ / ↓          결과 이동", "Enter          선택 실행", "Tab            자동완성", "→              액션 모드", "Escape         닫기 / 뒤로", "",
			"[ 기능 ]", "F1             도움말", "F2             파일 이름 바꾸기", "F5             인덱스 새로 고침", "Delete         항목 제거", "Ctrl+,         설정", "Ctrl+L         입력 초기화", "Ctrl+C         이름 복사", "Ctrl+H         클립보드 히스토리", "Ctrl+R         최근 실행",
			"Ctrl+B         즐겨찾기", "Ctrl+K         이 도움말", "Ctrl+1~9       N번째 실행", "Ctrl+Shift+C   경로 복사", "Ctrl+Shift+E   탐색기에서 열기", "Ctrl+Enter     관리자 실행", "Alt+Enter      속성 보기", "Shift+Enter    대형 텍스트"
		};
		CustomMessageBox.Show(string.Join("\n", value), "AX Commander — 단축키 도움말", MessageBoxButton.OK, MessageBoxImage.Asterisk);
	}

	private void ShowToast(string message, string icon = "\ue73e")
	{
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Expected O, but got Unknown
		ToastText.Text = message;
		ToastIcon.Text = icon;
		ToastOverlay.Visibility = Visibility.Visible;
		ToastOverlay.Opacity = 0.0;
		Storyboard storyboard = (Storyboard)FindResource("ToastFadeIn");
		storyboard.Begin(this);
		DispatcherTimer? indexStatusTimer = _indexStatusTimer;
		if (indexStatusTimer != null)
		{
			indexStatusTimer.Stop();
		}
		_indexStatusTimer = new DispatcherTimer
		{
			Interval = TimeSpan.FromSeconds(2.0)
		};
		_indexStatusTimer.Tick += delegate
		{
			_indexStatusTimer.Stop();
			Storyboard fadeOut = (Storyboard)FindResource("ToastFadeOut");
			EventHandler onCompleted = null;
			onCompleted = delegate
			{
				fadeOut.Completed -= onCompleted;
				ToastOverlay.Visibility = Visibility.Collapsed;
			};
			fadeOut.Completed += onCompleted;
			fadeOut.Begin(this);
		};
		_indexStatusTimer.Start();
	}

	private bool TryHandleSpecialAction()
	{
		if (!(_vm.SelectedItem?.Data is FileActionData { Action: var action } fileActionData))
		{
			return false;
		}
		switch (action)
		{
		case FileAction.DeleteToRecycleBin:
		{
			string path2 = fileActionData.Path;
			string fileName = System.IO.Path.GetFileName(path2);
			MessageBoxResult messageBoxResult = CustomMessageBox.Show("'" + fileName + "'\n\n이 항목을 휴지통으로 보내겠습니까?", "AX Copilot — 삭제 확인", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);
			if (messageBoxResult == MessageBoxResult.OK)
			{
				try
				{
					SendToRecycleBin(path2);
					_vm.ExitActionMode();
					ShowToast("휴지통으로 이동됨", "\ue74d");
				}
				catch (Exception ex)
				{
					CustomMessageBox.Show("삭제 실패: " + ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Hand);
				}
			}
			else
			{
				_vm.ExitActionMode();
			}
			return true;
		}
		case FileAction.Rename:
		{
			string path = fileActionData.Path;
			_vm.ExitActionMode();
			_vm.InputText = "rename " + path;
			((DispatcherObject)this).Dispatcher.BeginInvoke((Delegate)(Action)delegate
			{
				InputBox.CaretIndex = InputBox.Text.Length;
			}, (DispatcherPriority)5, Array.Empty<object>());
			return true;
		}
		default:
			return false;
		}
	}

	[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
	private static extern int SHFileOperation(ref SHFILEOPSTRUCT lpFileOp);

	private void SendToRecycleBin(string path)
	{
		SHFILEOPSTRUCT lpFileOp = new SHFILEOPSTRUCT
		{
			hwnd = new WindowInteropHelper(this).Handle,
			wFunc = 3u,
			pFrom = path + "\0",
			fFlags = 84
		};
		int num = SHFileOperation(ref lpFileOp);
		if (num != 0)
		{
			throw new Win32Exception(num, $"SHFileOperation 실패 (코드 {num})");
		}
	}

	private void ShowLargeType()
	{
		if (_vm.SelectedItem?.Data is ClipboardEntry clipboardEntry)
		{
			try
			{
				if (Application.Current is App app)
				{
					app.ClipboardHistoryService?.SuppressNextCapture();
				}
				if (!clipboardEntry.IsText && clipboardEntry.Image != null)
				{
					BitmapSource bitmapSource = ClipboardHistoryService.LoadOriginalImage(clipboardEntry.OriginalImagePath);
					BitmapSource bitmapSource2 = bitmapSource ?? clipboardEntry.Image;
					Clipboard.SetImage(bitmapSource2);
					string text;
					if (!string.IsNullOrEmpty(clipboardEntry.OriginalImagePath) && File.Exists(clipboardEntry.OriginalImagePath))
					{
						text = clipboardEntry.OriginalImagePath;
					}
					else
					{
						text = TempFileService.CreateTempFile("clip_image", ".png");
						PngBitmapEncoder pngBitmapEncoder = new PngBitmapEncoder();
						pngBitmapEncoder.Frames.Add(BitmapFrame.Create(bitmapSource2));
						using FileStream stream = new FileStream(text, FileMode.Create);
						pngBitmapEncoder.Save(stream);
					}
					Process.Start(new ProcessStartInfo(text)
					{
						UseShellExecute = true
					});
				}
				else if (!string.IsNullOrEmpty(clipboardEntry.Text))
				{
					Clipboard.SetText(clipboardEntry.Text);
					string text2 = TempFileService.CreateTempFile("clip_text", ".txt");
					File.WriteAllText(text2, clipboardEntry.Text, Encoding.UTF8);
					Process.Start(new ProcessStartInfo("notepad.exe", "\"" + text2 + "\"")
					{
						UseShellExecute = true
					});
				}
				return;
			}
			catch (Exception ex)
			{
				LogService.Warn("클립보드 외부 뷰어 실패: " + ex.Message);
				return;
			}
		}
		string largeTypeText = _vm.GetLargeTypeText();
		if (!string.IsNullOrWhiteSpace(largeTypeText))
		{
			new LargeTypeWindow(largeTypeText).Show();
		}
	}

	private void ResultList_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
	{
		object originalSource = e.OriginalSource;
		DependencyObject val = (DependencyObject)((originalSource is DependencyObject) ? originalSource : null);
		while (val != null && !(val is ListViewItem))
		{
			val = VisualTreeHelper.GetParent(val);
		}
		if (!(val is ListViewItem listViewItem))
		{
			return;
		}
		LauncherItem launcherItem = listViewItem.Content as LauncherItem;
		if (launcherItem == null)
		{
			return;
		}
		DateTime utcNow = DateTime.UtcNow;
		double totalMilliseconds = (utcNow - _lastClickTime).TotalMilliseconds;
		if (_lastClickedItem == launcherItem && totalMilliseconds < 600.0)
		{
			if (!_vm.IsActionMode && _vm.CanEnterActionMode())
			{
				_vm.EnterActionMode(launcherItem);
				e.Handled = true;
			}
			else
			{
				_vm.ExecuteSelectedAsync();
				e.Handled = true;
			}
			_lastClickedItem = null;
		}
		else
		{
			_lastClickedItem = launcherItem;
			_lastClickTime = utcNow;
		}
	}

	private void ResultList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
	{
		_vm.ExecuteSelectedAsync();
	}

	private void Window_Deactivated(object sender, EventArgs e)
	{
		if (_vm.CloseOnFocusLost)
		{
			Hide();
		}
	}

	private void ScrollToSelected()
	{
		if (_vm.SelectedItem != null)
		{
			ResultList.ScrollIntoView(_vm.SelectedItem);
		}
	}

	private void ShowNotification(string message)
	{
	}

	[DebuggerNonUserCode]
	[GeneratedCode("PresentationBuildTasks", "10.0.5.0")]
	public void InitializeComponent()
	{
		if (!_contentLoaded)
		{
			_contentLoaded = true;
			Uri resourceLocator = new Uri("/AxCopilot;component/views/launcherwindow.xaml", UriKind.Relative);
			Application.LoadComponent(this, resourceLocator);
		}
	}

	[DebuggerNonUserCode]
	[GeneratedCode("PresentationBuildTasks", "10.0.5.0")]
	[EditorBrowsable(EditorBrowsableState.Never)]
	void IComponentConnector.Connect(int connectionId, object target)
	{
		switch (connectionId)
		{
		case 1:
			((LauncherWindow)target).Loaded += Window_Loaded;
			((LauncherWindow)target).Deactivated += Window_Deactivated;
			((LauncherWindow)target).PreviewKeyDown += Window_PreviewKeyDown;
			((LauncherWindow)target).KeyDown += Window_KeyDown;
			break;
		case 2:
			RainbowGlowBorder = (Border)target;
			break;
		case 3:
			LauncherRainbowBrush = (LinearGradientBrush)target;
			break;
		case 4:
			MainBorder = (Border)target;
			break;
		case 5:
			DiamondIcon = (Canvas)target;
			DiamondIcon.MouseLeftButtonDown += DiamondIcon_Click;
			break;
		case 6:
			IconRotate = (RotateTransform)target;
			break;
		case 7:
			IconScale = (ScaleTransform)target;
			break;
		case 8:
			GlowBlue = (Rectangle)target;
			break;
		case 9:
			GlowGreen1 = (Rectangle)target;
			break;
		case 10:
			GlowGreen2 = (Rectangle)target;
			break;
		case 11:
			GlowRed = (Rectangle)target;
			break;
		case 12:
			PixelBlue = (Rectangle)target;
			break;
		case 13:
			PixelGreen1 = (Rectangle)target;
			break;
		case 14:
			PixelGreen2 = (Rectangle)target;
			break;
		case 15:
			PixelRed = (Rectangle)target;
			break;
		case 16:
			InputBox = (TextBox)target;
			InputBox.TextChanged += InputBox_TextChanged;
			break;
		case 17:
			ResultList = (ListView)target;
			ResultList.PreviewMouseLeftButtonUp += ResultList_PreviewMouseLeftButtonUp;
			ResultList.MouseDoubleClick += ResultList_MouseDoubleClick;
			break;
		case 18:
			IndexStatusText = (TextBlock)target;
			break;
		case 19:
			ToastOverlay = (Border)target;
			break;
		case 20:
			ToastIcon = (TextBlock)target;
			break;
		case 21:
			ToastText = (TextBlock)target;
			break;
		default:
			_contentLoaded = true;
			break;
		}
	}
}
