using Avalonia.Collections;
using Avalonia.Controls;
using CommunityToolkit.Mvvm.Input;
using PSCHelpdesk.Services;
using PSCHelpdesk.Shared.ViewModels;

namespace PSCHelpdesk.ViewModels;

class PluginListViewModel : ViewModelBase, IViewModelBase
{
    public RelayCommand<object> LoadAllPluginsCommand { get; set; }
    public RelayCommand<object> UnLoadAllPluginsCommand { get; set; }
    public RelayCommand<object> LoadPluginCommand { get; set; }
    public AvaloniaList<string> Plugins { get; set; }
    public UserControl CurrentControl { get; set; }
        
    private PluginService _pluginService { get; }
        
    public PluginListViewModel(PluginManager pluginService)
    {
        this.Plugins = new AvaloniaList<string>();
            
        LoadPluginCommand = new RelayCommand<object>(LoadPlugin);
        LoadAllPluginsCommand = new RelayCommand<object>(LoadAllPlugins);
        UnLoadAllPluginsCommand = new RelayCommand<object>(UnLoadAllPlugins);
            
        /*foreach (var plugin in pluginService.GetPlugins())
        {
            this.Plugins.Add(plugin.Key);
        }*/

        //this._pluginService = pluginService;
    }
        
    async void LoadPlugin(object parameter)
    {
        this._pluginService.LoadPlugin(parameter.ToString());
    }

    async void LoadAllPlugins(object parameter)
    {
        foreach (var plugin in Plugins)
        {
            this._pluginService.LoadPlugin(plugin);
        }
    }

    async void UnLoadAllPlugins(object parameter)
    {
            
    }
        
}