using System;
using System.Collections.ObjectModel;
using System.Linq;

namespace QC.QMine.QMineInterface;

[Serializable]
public class RecentFileCollection : ObservableCollection<RecentFileItem>
{
	private int maxRecentFileCount = 10;

	public int MaxRecentFileCount
	{
		get
		{
			return maxRecentFileCount;
		}
		set
		{
			maxRecentFileCount = value;
		}
	}

	protected override void InsertItem(int index, RecentFileItem fileItem)
	{
		if (this.Any((RecentFileItem recentFileItem) => recentFileItem.FilePath == fileItem.FilePath))
		{
			MoveItem(IndexOf(this.First((RecentFileItem recentFileItem) => recentFileItem.FilePath == fileItem.FilePath)), 0);
			return;
		}
		if (MaxRecentFileCount == base.Count)
		{
			RemoveAt(base.Count - 1);
			index--;
		}
		base.InsertItem(index, fileItem);
	}
}
