using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;

namespace QFDT_Components;

public partial class ProductInformation : UserControl, IComponentConnector
{
	public class Resource
	{
		public string Caption;

		public string ResourceText;
	}

	public const int MAX_RESOURCES = 5;

	private Button[] buttons;

	private string[] resources;

	private string m_ProductDirectory;

	public ProductInformation()
	{
		InitializeComponent();
		buttons = new Button[5];
		buttons[0] = bn_Resource1;
		buttons[1] = bn_Resource2;
		buttons[2] = bn_Resource3;
		buttons[3] = bn_Resource4;
		buttons[4] = bn_Resource5;
		resources = new string[5];
	}

	public void SetupUI(List<Resource> list, string ProductDirectory)
	{
		ClearContent();
		int num = 0;
		for (num = 0; num < list.Count; num++)
		{
			buttons[num].Content = list[num].Caption;
			resources[num] = list[num].ResourceText;
			if (list[num].Caption.Length == 0)
			{
				buttons[num].Visibility = Visibility.Hidden;
			}
			else
			{
				buttons[num].Visibility = Visibility.Visible;
			}
		}
		for (num = list.Count; num < 5; num++)
		{
			buttons[num].Visibility = Visibility.Hidden;
		}
		m_ProductDirectory = ProductDirectory;
	}

	public void ClearContent()
	{
		for (int i = 0; i < 5; i++)
		{
			buttons[i].Content = "";
			resources[i] = "";
		}
		m_ProductDirectory = "";
	}

	private void bn_Resource_Click(object sender, RoutedEventArgs e)
	{
		Button button = (Button)sender;
		string text = "";
		if (button == bn_Resource1)
		{
			text = resources[0];
		}
		else if (button == bn_Resource2)
		{
			text = resources[1];
		}
		else if (button == bn_Resource3)
		{
			text = resources[2];
		}
		else if (button == bn_Resource4)
		{
			text = resources[3];
		}
		else if (button == bn_Resource5)
		{
			text = resources[4];
		}
		bool flag = false;
		try
		{
			if (Uri.TryCreate(text, UriKind.Absolute, out var result) && (result.Scheme == Uri.UriSchemeHttps || result.Scheme == Uri.UriSchemeHttp))
			{
				Process process = new Process();
				process.StartInfo.FileName = text;
				process.Start();
			}
			else if (text.Length > 0 && File.Exists(Path.Combine(m_ProductDirectory, text)))
			{
				Process process2 = new Process();
				process2.StartInfo.FileName = Path.Combine(m_ProductDirectory, text);
				process2.Start();
			}
		}
		catch
		{
		}
	}
}
