using System.IO;
using System.Reflection;
using System.Runtime.Versioning;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Navigation;
using QC.QMine.QMineInterface;

namespace QC.QMine;

public partial class About : Window, IComponentConnector
{
	public string AssemblyTitle
	{
		get
		{
			AssemblyTitleAttribute assemblyAttribute = GetAssemblyAttribute<AssemblyTitleAttribute>();
			if (assemblyAttribute != null)
			{
				return assemblyAttribute.Title;
			}
			return string.Empty;
		}
	}

	public string AssemblyVersion
	{
		get
		{
			AssemblyInformationalVersionAttribute assemblyAttribute = GetAssemblyAttribute<AssemblyInformationalVersionAttribute>();
			if (assemblyAttribute != null)
			{
				return assemblyAttribute.InformationalVersion;
			}
			return string.Empty;
		}
	}

	public string FrameworkVersion
	{
		get
		{
			TargetFrameworkAttribute assemblyAttribute = GetAssemblyAttribute<TargetFrameworkAttribute>();
			if (assemblyAttribute != null)
			{
				return assemblyAttribute.FrameworkDisplayName;
			}
			return string.Empty;
		}
	}

	public string AssemblyDescription
	{
		get
		{
			AssemblyDescriptionAttribute assemblyAttribute = GetAssemblyAttribute<AssemblyDescriptionAttribute>();
			if (assemblyAttribute != null)
			{
				return assemblyAttribute.Description;
			}
			return string.Empty;
		}
	}

	public string AssemblyProduct
	{
		get
		{
			AssemblyProductAttribute assemblyAttribute = GetAssemblyAttribute<AssemblyProductAttribute>();
			if (assemblyAttribute != null)
			{
				return assemblyAttribute.Product;
			}
			return string.Empty;
		}
	}

	public string AssemblyCopyright
	{
		get
		{
			AssemblyCopyrightAttribute assemblyAttribute = GetAssemblyAttribute<AssemblyCopyrightAttribute>();
			if (assemblyAttribute != null)
			{
				return assemblyAttribute.Copyright;
			}
			return string.Empty;
		}
	}

	public string AssemblyCompany
	{
		get
		{
			AssemblyCompanyAttribute assemblyAttribute = GetAssemblyAttribute<AssemblyCompanyAttribute>();
			if (assemblyAttribute != null)
			{
				return assemblyAttribute.Company;
			}
			return string.Empty;
		}
	}

	public string AssemblyBuildDate => new FileInfo(Assembly.GetExecutingAssembly().Location).LastWriteTime.ToString();

	public About()
	{
		InitializeComponent();
	}

	public T GetAssemblyAttribute<T>() where T : class
	{
		object[] customAttributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(T), inherit: false);
		if (customAttributes.Length == 1)
		{
			return customAttributes[0] as T;
		}
		return null;
	}

	private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
	{
		CommonFunctions.LaunchEmailClient("mailto:qmine.help@qualcomm.com");
		e.Handled = true;
	}
}
