using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using Microsoft.Win32;
using Qualcomm_ModemRFA;

namespace QFDT_Components;

public partial class PCF_WWAN_CFG : UserControl, IComponentConnector
{
	public PCF_WWAN_CFG()
	{
		InitializeComponent();
		cbxCalVer.Items.Clear();
		cbxCalVer.Items.Add(Cal_Version.V4.ToString());
		cbxCalVer.Items.Add(Cal_Version.QSC.ToString());
		cbxCalVer.SelectedItem = Cal_Version.V4.ToString();
		cbxPlatform.Items.Clear();
		cbxPlatform.Items.Add(Platform.AT.ToString());
		cbxPlatform.Items.Add(Platform.HE.ToString());
		cbxPlatform.SelectedItem = Platform.AT.ToString();
	}

	public void UpdateTXTUI(TextBox txt, string sValue)
	{
		txt.Text = sValue;
	}

	private void WWAN_bnBrowseXTT_Click(object sender, RoutedEventArgs e)
	{
		OpenFileDialog openFileDialog = new OpenFileDialog();
		openFileDialog.DefaultExt = ".xtt";
		openFileDialog.Filter = "Calibration XTT (*.xtt)|*.xtt";
		if (openFileDialog.ShowDialog() == true)
		{
			string fileName = openFileDialog.FileName;
			WWAN_txtXTTPath.Text = fileName;
		}
	}

	private void WWAN_bnBrowseRefQCN_Click(object sender, RoutedEventArgs e)
	{
		OpenFileDialog openFileDialog = new OpenFileDialog();
		openFileDialog.DefaultExt = ".qcn";
		openFileDialog.Filter = "Reference QCN (*.qcn)|*.qcn|XQCN (*.xqcn)|*.xqcn";
		if (openFileDialog.ShowDialog() == true)
		{
			string fileName = openFileDialog.FileName;
			WWAN_txtRefQCNPath.Text = fileName;
		}
	}

	private void RefreshAccordingToCalVersion()
	{
		spImportV4.Visibility = ((!((string)cbxCalVer.SelectedItem == Cal_Version.V4.ToString())) ? Visibility.Collapsed : Visibility.Visible);
		if ((string)cbxCalVer.SelectedItem == Cal_Version.QSC.ToString())
		{
			lbPlatform.Visibility = Visibility.Visible;
			cbxPlatform.Visibility = Visibility.Visible;
			if (GloVar.MPSSVersion.Contains(".HE."))
			{
				cbxPlatform.SelectedValue = "HE";
			}
		}
		else
		{
			lbPlatform.Visibility = Visibility.Hidden;
			cbxPlatform.Visibility = Visibility.Hidden;
		}
	}

	private void cboCalVersion_selectionChanged(object sender, SelectionChangedEventArgs e)
	{
		RefreshAccordingToCalVersion();
	}

	private void cboPlatform_selectionChanged(object sender, SelectionChangedEventArgs e)
	{
	}
}
