using MudBlazor;
using VisionBuilder.UI.Blazor.Dialogs;
using VisionBuilder.UI.Common.Services;

namespace VisionBuilder.UI.Blazor.Services;

public class BlazorPasswordInputService : IPasswordInputService
{
    private IDialogService? _dialogService;

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

    public async Task<string?> GetPasswordAsync()
    {
        if (_dialogService == null)
            return null;

        var dialog = await _dialogService.ShowAsync<PasswordInputDialog>("Password Required");
        var result = await dialog.Result;
        if (result != null && !result.Canceled)
            return result.Data as string;
        return null;
    }
}
