using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;

namespace QC.QMine.QMineInterface;

[Serializable]
public class FileSystemItemsGroup : BindableObject
{
	private string groupName = "<no group>";

	private readonly string defaultGroupName = "<Default group>";

	private ObservableCollection<FileSystemItem> fileSystemItemsList = new ObservableCollection<FileSystemItem>();

	private bool isSelected;

	public string GroupName
	{
		get
		{
			return groupName;
		}
		set
		{
			if (!(groupName == value))
			{
				groupName = value;
				OnPropertyChanged("GroupName");
			}
		}
	}

	public ObservableCollection<FileSystemItem> FileSystemItemsList
	{
		get
		{
			return fileSystemItemsList;
		}
		set
		{
			fileSystemItemsList = value;
		}
	}

	public bool IsSelected
	{
		get
		{
			return isSelected;
		}
		set
		{
			if (isSelected != value)
			{
				isSelected = value;
				OnPropertyChanged("IsSelected");
			}
		}
	}

	public FileSystemItemsGroup()
	{
		FileSystemItemsList.CollectionChanged += EstablishParentChildRelationOnCollectionChanged;
		FileSystemItemsList.CollectionChanged += FileSystemItemsList_CollectionChanged;
	}

	private void FileSystemItemsList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
	{
		OnPropertyChanged("FileSystemItemsList");
	}

	public override void Changed(string changedFieldName)
	{
		if (changedFieldName != "IsSelected")
		{
			base.Changed(changedFieldName);
		}
	}

	public List<FileItem> GetFiles()
	{
		List<FileItem> list = new List<FileItem>();
		foreach (FileSystemItem fileSystemItems in FileSystemItemsList)
		{
			if (fileSystemItems is FileItem)
			{
				list.Add((FileItem)fileSystemItems);
			}
			if (!(fileSystemItems is FolderItem))
			{
				continue;
			}
			FolderItem folderItem = (FolderItem)fileSystemItems;
			List<string> files = folderItem.GetFiles();
			foreach (string item in files)
			{
				FileItem fileItem = new FileItem();
				fileItem.FullPath = item;
				FileItem fileItem2 = fileItem;
				if (CommonFunctions.IsQtmFile(item))
				{
					fileItem2.IsSuiteFile = false;
				}
				list.Add(fileItem2);
			}
		}
		return list;
	}
}
