using System;
using ReactiveUI;
using Serilog;
using xwd.utils;

namespace detect.gui.ViewModels;

public class WebViewModel : ViewModelBase
{
    private readonly string[] _localRoutes =
    [
        "#/dashboard",
        "#/data/task", 
        "#/data/device", 
        "#/system/log",
        "#/system/user" 
    ];

    private string? _address;

    public string? Address
    {
        get => _address;
        set => this.RaiseAndSetIfChanged(ref _address, value);
    }

    public void SetAddress(int index)
    {
        var isOnLine = AppSettingsManager.Manager().GetBool("Embedded.IsOnline");
        var path = AppSettingsManager.Manager().GetString("Embedded.Path", "./dist/index.html");
        var prefix = isOnLine ? path : AppDomain.CurrentDomain.BaseDirectory + path;
        Address = $"{prefix}{_localRoutes[index]}";
        Log.Information("current address: {address}", Address);
    }
}