// EN: Centralized helper for shop vertical/category utilities.
// VI: Helper tập trung cho các tiện ích ngành hàng cửa hàng.
//
// Consolidates duplicate GetShopIcon, GetVerticalLabel, NormalizeVertical
// logic that was scattered across Dashboard.razor, ShopOverview.razor,
// and ShopSidebarConfig.cs.

namespace WebClientTpos.Client.Services;

/// <summary>
/// EN: Centralized utilities for shop vertical display — icon, label, normalize.
/// VI: Tiện ích tập trung cho hiển thị ngành hàng — icon, label, chuẩn hóa.
/// </summary>
public static class ShopVerticalHelper
{
    /// <summary>
    /// EN: Normalize category string to internal vertical key.
    /// VI: Chuẩn hóa chuỗi category thành key nội bộ.
    /// </summary>
    public static string NormalizeVertical(string? category) => (category ?? "").ToLowerInvariant() switch
    {
        "cafe" or "café" or "coffee" or "foodbeverage" => "cafe",
        "restaurant" or "nhà hàng" or "bar" => "restaurant",
        "karaoke" or "entertainment" => "karaoke",
        "spa" or "services" => "spa",
        "beauty" or "salon" or "thẩm mỹ" => "beauty",
        "retail" => "retail",
        _ => "default"
    };

    /// <summary>
    /// EN: Get Lucide icon name for a shop vertical/category.
    /// VI: Lấy tên icon Lucide cho ngành hàng.
    /// </summary>
    public static string GetIcon(string? category) => NormalizeVertical(category) switch
    {
        "cafe" => "coffee",
        "restaurant" => "utensils",
        "karaoke" => "mic",
        "spa" => "sparkles",
        "beauty" => "scissors",
        "retail" => "shopping-bag",
        _ => "store"
    };

    /// <summary>
    /// EN: Get display label for a vertical.
    /// VI: Lấy tên hiển thị cho ngành hàng.
    /// </summary>
    public static string GetLabel(string? category) => NormalizeVertical(category) switch
    {
        "cafe" => "Café",
        "restaurant" => "Nhà hàng / Bar",
        "karaoke" => "Karaoke",
        "spa" => "Spa & Wellness",
        "beauty" => "Thẩm mỹ viện",
        "retail" => "Bán lẻ",
        _ => "Cửa hàng"
    };

    /// <summary>
    /// EN: Get accent color CSS value for a vertical.
    /// VI: Lấy màu nhấn CSS cho ngành hàng.
    /// </summary>
    public static string GetColor(string? category) => NormalizeVertical(category) switch
    {
        "cafe" => "var(--admin-orange-primary)",
        "restaurant" => "#3B82F6",
        "karaoke" => "#8B5CF6",
        "spa" => "#EC4899",
        "beauty" => "#A855F7",
        "retail" => "#22C55E",
        _ => "var(--admin-orange-primary)"
    };

    /// <summary>
    /// EN: Get background color (RGBA) for a vertical.
    /// VI: Lấy màu nền (RGBA) cho ngành hàng.
    /// </summary>
    public static string GetBgColor(string? category) => NormalizeVertical(category) switch
    {
        "cafe" => "rgba(255,92,0,0.125)",
        "restaurant" => "rgba(59,130,246,0.125)",
        "karaoke" => "rgba(139,92,246,0.125)",
        "spa" => "rgba(236,72,153,0.125)",
        "beauty" => "rgba(168,85,247,0.125)",
        "retail" => "rgba(34,197,94,0.125)",
        _ => "rgba(255,92,0,0.125)"
    };

    // ─── Shop Status Helpers (shared across StoreList, ShopOverview, etc.) ───

    /// <summary>
    /// EN: Get CSS badge class for shop status.
    /// VI: Lấy CSS badge class cho trạng thái shop.
    /// </summary>
    public static string GetStatusBadgeClass(string? status) => status?.ToLowerInvariant() switch
    {
        "published" or "active" => "online",
        "draft" or "setup" => "setup",
        "inactive" or "paused" => "paused",
        _ => "setup"
    };

    /// <summary>
    /// EN: Get display label for shop status.
    /// VI: Lấy nhãn hiển thị cho trạng thái shop.
    /// </summary>
    public static string GetStatusLabel(string? status) => status?.ToLowerInvariant() switch
    {
        "published" or "active" => "Đang mở",
        "draft" or "setup" => "Thiết lập",
        "inactive" or "paused" => "Tạm dừng",
        "closed" => "Đã đóng",
        _ => status ?? "—"
    };

    public static bool IsActive(string? status) =>
        status?.Equals("Published", StringComparison.OrdinalIgnoreCase) == true
        || status?.Equals("active", StringComparison.OrdinalIgnoreCase) == true;

    public static bool IsSetup(string? status) =>
        status?.Equals("Draft", StringComparison.OrdinalIgnoreCase) == true
        || status?.Equals("setup", StringComparison.OrdinalIgnoreCase) == true;

    public static bool IsPaused(string? status) =>
        status?.Equals("Inactive", StringComparison.OrdinalIgnoreCase) == true
        || status?.Equals("paused", StringComparison.OrdinalIgnoreCase) == true;
}
