using System.Threading.Tasks;
using Microsoft.JSInterop;

namespace BlazorClient
{
  /// <summary>
  /// Service permettant d'accéder au local storage du navigateur.
  /// </summary>
  public class LocalStorage
  {
    private readonly IJSRuntime _js;

    public LocalStorage(IJSRuntime js)
    {
      _js = js;
    }

    public async Task Save(string key, string value)
    {
      await _js.InvokeVoidAsync("setLocalItem", key, value);
    }

    public async Task<string> Get(string key)
    {
      return await _js.InvokeAsync<string>("getLocalItem", key);
    }
  }
}