using Inspectron.Settings;
using MudBlazor;
using VisionBuilder.UI.Blazor.Dialogs;
using VisionBuilder.UI.Common.ViewModel.Interfaces.UI;

namespace VisionBuilder.UI.Blazor.Services;

public class BlazorSettingsService : ISettingsService
{
    private readonly InspectronSettings _settings;
    private IDialogService? _dialogService;

    public BlazorSettingsService(InspectronSettings settings)
    {
        _settings = settings;
    }

    public void SetDialogService(IDialogService dialogService)
    {
        _dialogService = dialogService;
    }

    public async Task ShowSettingsDialogAsync()
    {
        if (_dialogService == null)
            return;

        var parameters = new DialogParameters<SettingsDialog>
        {
            { x => x.Settings, _settings }
        };
        var options = new DialogOptions
        {
            MaxWidth = MaxWidth.Medium,
            FullWidth = true
        };
        var dialog = await _dialogService.ShowAsync<SettingsDialog>("Settings", parameters, options);
        await dialog.Result;
    }
}
