using Gready_Poang.CommandClasses;
using Gready_Poang.Core;

namespace Gready_Poang.LocalServices;

public class SplashService : ISplashService
{
    private readonly SplashViewModelCommands _viewModel;

    public SplashService(SplashViewModelCommands viewModel)
    {
        _viewModel = viewModel;
    }

    public async Task ShowSplash(string text = "Välkommen!", int durationMs = 3000)
    {
        _viewModel.SplashText = text;
        _viewModel.SplashOpacity = 0.8;
        _viewModel.SplashBackgroundColor = Colors.DodgerBlue;
        _viewModel.IsSplashVisible = true;
        //await Task.Yield(); // ger UI-tråden en chans att uppdatera
        if (durationMs > 0)
        {
            await Task.Delay(durationMs);
            _viewModel.IsSplashVisible = false;
        }
    }

    public async Task HideAsync()
    {
        //_viewModel.IsSplashVisible = false;
        await _viewModel.HideSplashAsync();
    }
}
