using Microsoft.JSInterop; using System.Text.Json; namespace HushianWebApp.Services { public interface ILocalStorageService { Task GetItem(string key); Task SetItem(string key, T value); Task RemoveItem(string key); } public class LocalStorageService : ILocalStorageService { private IJSRuntime _jsRuntime; public LocalStorageService(IJSRuntime jsRuntime) { _jsRuntime = jsRuntime; } public async Task GetItem(string key) { var json = await _jsRuntime.InvokeAsync("localStorage.getItem", key); if (json == null) return default; return JsonSerializer.Deserialize(json); } public async Task SetItem(string key, T value) { await _jsRuntime.InvokeVoidAsync("localStorage.setItem", key, JsonSerializer.Serialize(value)); } public async Task RemoveItem(string key) { await _jsRuntime.InvokeVoidAsync("localStorage.removeItem", key); } } }