using AyCode.Core.Enums;
using AyCode.Core.Loggers;
using Microsoft.JSInterop;

namespace AyCode.Services.Loggers;

//public interface IBrowserConsoleLogWriter : IAcLogWriterBase
//{ }

//public abstract class LogWriterClient : AcTextLogWriterBase
//{
//    protected LogWriterClient(IJSRuntime jsRuntime) : base(AppType.Web, LogLevel.Debug)
//    { }
//}

public class AcBrowserConsoleLogWriter : AcTextLogWriterBase, IAcLogWriterClientBase
{
    protected readonly IJSRuntime JsRuntime;

    protected readonly Dictionary<LogLevel, string> InvokeConsoleNames = new()
    {
        [LogLevel.Detail] = "console.info", //trace
        [LogLevel.Trace] = "console.info",
        [LogLevel.Debug] = "console.info",
        [LogLevel.Info] = "console.info",
        [LogLevel.Suggest] = "console.info",
        [LogLevel.Warning] = "console.warn",
        [LogLevel.Error] = "console.error"
    };

    protected AcBrowserConsoleLogWriter(IJSRuntime jsRuntime, AppType appType = AppType.Web, LogLevel logLevel = LogLevel.Info) : base(appType, logLevel)
    {
        JsRuntime = jsRuntime;
    }

    protected override void WriteText(string? logText, LogLevel logLevel)
    {
        JsRuntime.InvokeVoidAsync(InvokeConsoleNames[logLevel], logText); //logText?.Replace(Environment.NewLine, "<br />"));
    }

    //public void Info(string message)
    //{
    //    ((AcLogWriterBase)this).Info(message);
    //    //jsRuntime.InvokeVoidAsync("console.log", logText);
    //}
}