using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace skyscraper5.UI.StreamAcquisition
{
	partial class StreamAcquirerPickingForm : Form
	{
		public StreamAcquirerPickingForm(List<StreamAcquirerListItem> streamAcquirers, string[] args)
		{
			InitializeComponent();
			Args = args;

			foreach (StreamAcquirerListItem streamAcquirer in streamAcquirers)
			{
				if (streamAcquirer.Hidden)
					continue;

				listView1.Items.Add(streamAcquirer);
			}
		}

		public string[] Args { get; }
		public StreamSource StreamSource { get; private set; }


		private void button1_Click(object sender, EventArgs e)
		{
			ListViewItem lvi = listView1.SelectedItems[0];
			StreamAcquirerListItem sali = (StreamAcquirerListItem)lvi;
			object o = sali.Wrapped.BaseAskUserForHandle(this);
			if (o != null)
			{
				StreamSource resultStream = sali.Wrapped.BaseGetStream(o);
				if (resultStream != null)
				{
					DialogResult = DialogResult.OK;
					StreamSource = resultStream;
					Close();
				}
			}
		}

		private void listView1_SelectedIndexChanged(object sender, EventArgs e)
		{
			button1.Enabled = listView1.SelectedItems.Count > 0;
		}

		private void button2_Click(object sender, EventArgs e)
		{
			DialogResult = DialogResult.Cancel;
			Close();
		}

		private void listView1_DoubleClick(object sender, EventArgs e)
		{
			if (listView1.SelectedItems.Count != 1)
				return;

			button1_Click(sender, e);
		}
	}
}
