using System;
using System.Collections.ObjectModel;
using System.Windows;

namespace QC.QMine.QMineInterface;

public class OutputLogCollection : ObservableCollection<OutputLog>
{
	private static int elementCounter = 1;

	private int maxItems = 2;

	public int MaxItems
	{
		get
		{
			return maxItems;
		}
		set
		{
			maxItems = value;
		}
	}

	protected override void InsertItem(int index, OutputLog item)
	{
		if (base.Count == MaxItems)
		{
			RemoveAt(0);
			index--;
		}
		item.DisplayName = "Output " + elementCounter++;
		base.InsertItem(index, item);
	}

	public void StartNewLog()
	{
		Action<OutputLog> action = null;
		action = base.Add;
		Application.Current.Dispatcher.Invoke(action, new OutputLog());
	}

	public void WriteLogMessageToCurrentLog(string message, bool newLine = true)
	{
		if (base.Count > 0)
		{
			base[base.Count - 1].WriteLogMessage(message, newLine);
		}
	}
}
