using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using CommunityToolkit.Mvvm.DependencyInjection;
using PSCHelpdesk.Plugins.HetznerServer.Models;
using PSCHelpdesk.Plugins.HetznerServer.ViewModels;
using PSCHelpdesk.Shared.Service;
using PSCHelpdesk.Shared.Setting;

namespace PSCHelpdesk.Plugins.HetznerServer.Views;

public partial class HetznerSettingsView : UserControl
{
    private SettingsManager settingsManager;
    private Settings settings;
    public HetznerSettingsView()
    {
        InitializeComponent();
        
        settingsManager = (SettingsManager)Ioc.Default.GetService<ISettingsManager>();
        settings = new Settings();
        settingsManager.LoadPluginSettings("HetznerSettings", settings);
        
    }

    private void SaveSettings_OnClick(object? sender, RoutedEventArgs e)
    {
        settings.HetznerApiKey = ((HetznerSettingsViewModel)this.DataContext).ApiKey;
        settingsManager.SavePluginSettings("HetznerSettings", settings);
    }
}