using Microsoft.AspNetCore.Components;

namespace WebClientTpos.Client.Pages.SuperAdmin;

/// <summary>
/// EN: Base class for all Super Admin pages — auth restore + common helpers.
/// VI: Lớp cơ sở cho tất cả trang Super Admin — khôi phục auth + helpers chung.
/// </summary>
public abstract class SuperAdminBase : ComponentBase
{
    [Inject] protected NavigationManager NavigationManager { get; set; } = default!;
    [Inject] protected Services.AuthService AuthService { get; set; } = default!;

    protected override async Task OnInitializedAsync()
    {
        await AuthService.TryRestoreSessionAsync("owner");
    }

    protected string SearchQuery { get; set; } = string.Empty;
    protected bool IsLoading { get; set; } = false;

    protected void NavigateTo(string path)
    {
        NavigationManager.NavigateTo($"/superadmin/{path}");
    }

    protected static string FormatCurrency(decimal amount)
    {
        if (amount >= 1_000_000_000) return $"{amount / 1_000_000_000:0.#}B";
        if (amount >= 1_000_000) return $"{amount / 1_000_000:0.#}M";
        if (amount >= 1_000) return $"{amount / 1_000:0.#}K";
        return amount.ToString("N0");
    }

    protected static string FormatNumber(int number)
    {
        if (number >= 1_000_000) return $"{number / 1_000_000.0:0.#}M";
        if (number >= 1_000) return $"{number / 1_000.0:0.#}K";
        return number.ToString("N0");
    }

    protected static string GetTodayFormatted() => DateTime.Now.ToString("dd/MM/yyyy");
}
