using System.Drawing;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media;

namespace AxCopilot.Views;

internal sealed class ModernColorTable : ProfessionalColorTable
{
	private static System.Drawing.Color Bg => TC("LauncherBackground", System.Drawing.Color.FromArgb(250, 250, 252));

	private static System.Drawing.Color Hover => TC("ItemHoverBackground", System.Drawing.Color.FromArgb(234, 234, 247));

	private static System.Drawing.Color Border => TC("BorderColor", System.Drawing.Color.FromArgb(210, 210, 232));

	private static System.Drawing.Color Sep => TC("SeparatorColor", System.Drawing.Color.FromArgb(228, 228, 242));

	public override System.Drawing.Color MenuBorder => Border;

	public override System.Drawing.Color ToolStripDropDownBackground => Bg;

	public override System.Drawing.Color ImageMarginGradientBegin => Bg;

	public override System.Drawing.Color ImageMarginGradientMiddle => Bg;

	public override System.Drawing.Color ImageMarginGradientEnd => Bg;

	public override System.Drawing.Color MenuItemSelected => Hover;

	public override System.Drawing.Color MenuItemSelectedGradientBegin => Hover;

	public override System.Drawing.Color MenuItemSelectedGradientEnd => Hover;

	public override System.Drawing.Color MenuItemBorder => System.Drawing.Color.Transparent;

	public override System.Drawing.Color MenuItemPressedGradientBegin => Hover;

	public override System.Drawing.Color MenuItemPressedGradientEnd => Hover;

	public override System.Drawing.Color SeparatorLight => Sep;

	public override System.Drawing.Color SeparatorDark => Sep;

	public override System.Drawing.Color CheckBackground => System.Drawing.Color.Transparent;

	public override System.Drawing.Color CheckSelectedBackground => System.Drawing.Color.Transparent;

	public override System.Drawing.Color CheckPressedBackground => System.Drawing.Color.Transparent;

	private static System.Drawing.Color TC(string key, System.Drawing.Color fb)
	{
		try
		{
			if (System.Windows.Application.Current?.Resources[key] is SolidColorBrush { Color: var color } solidColorBrush)
			{
				return System.Drawing.Color.FromArgb(color.A, solidColorBrush.Color.R, solidColorBrush.Color.G, solidColorBrush.Color.B);
			}
		}
		catch
		{
		}
		return fb;
	}
}
