using Crysome.Server.Model;
using Crysome.Server.Network;

namespace Crysome.Server.ViewModel;

public class MainViewModel : ViewModelBase
{
	private ViewModelBase _currentPageViewModel;

	public ViewModelBase CurrentPageViewModel
	{
		get
		{
			return _currentPageViewModel;
		}
		set
		{
			_currentPageViewModel = value;
			OnPropertyChanged("CurrentPageViewModel");
		}
	}

	public ManageClientsViewModel ClientsVM { get; private set; }

	public MainViewModel()
	{
		ClientsVM = new ManageClientsViewModel(this);
		CurrentPageViewModel = ClientsVM;
	}

	public void GoToClients()
	{
		if (CurrentPageViewModel is FileExplorerViewModel fileExplorerViewModel)
		{
			fileExplorerViewModel.Dispose();
		}
		CurrentPageViewModel = ClientsVM;
	}

	public void GoToBuilder()
	{
		CurrentPageViewModel = new BuilderViewModel(this);
	}

	public void GoToFileExplorer(CrysomeServer server, ClientInfo client)
	{
		if (CurrentPageViewModel is FileExplorerViewModel fileExplorerViewModel)
		{
			fileExplorerViewModel.Dispose();
		}
		CurrentPageViewModel = new FileExplorerViewModel(server, client, this);
	}

	public void GoToSettings()
	{
		CurrentPageViewModel = new SettingsViewModel(this, ClientsVM.Store);
	}

	public void GoToPlugins()
	{
		CurrentPageViewModel = new PluginManagerViewModel(this, ClientsVM.Store);
	}
}
