@namespace Lumeo
@using Blazicons

<Blazicon Svg="@ResolvedSvg" class="@CssClass" @attributes="AdditionalAttributes" />

@code {
    /// <summary>
    /// Lucide icon name (PascalCase, e.g. "Search", "ChevronDown", "TrendingUp").
    /// Unknown names fall back to a Circle. Use <see cref="Svg"/> to supply any
    /// icon directly (Lucide or any other Blazicons library).
    /// </summary>
    [Parameter] public string? Name { get; set; }

    /// <summary>
    /// Direct Blazicons <see cref="SvgIcon"/> reference — takes precedence over <see cref="Name"/>.
    /// Lets consumers use any icon library (Lucide, Bootstrap, FluentUI, Material, FontAwesome, Ionicons, MDI).
    /// </summary>
    [Parameter] public SvgIcon? Svg { get; set; }

    /// <summary>Size preset. Sets Tailwind <c>h-{n} w-{n}</c> on the SVG. Defaults to <see cref="IconSize.Md"/> (h-4 w-4).</summary>
    [Parameter] public IconSize Size { get; set; } = IconSize.Md;

    [Parameter] public string? Class { get; set; }
    [Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AdditionalAttributes { get; set; }

    private SvgIcon ResolvedSvg => Svg ?? MapName(Name);

    private string CssClass => $"{SizeClass} {Class}".Trim();

    private string SizeClass => Size switch
    {
        IconSize.Xs => "h-3 w-3",
        IconSize.Sm => "h-3.5 w-3.5",
        IconSize.Lg => "h-5 w-5",
        IconSize.Xl => "h-6 w-6",
        _ => "h-4 w-4",
    };

    // Common UI icon name → Lucide mapping. Covers the set used across Lumeo's
    // own components plus the typical app chrome vocabulary. Unknown names fall
    // back to Circle — consumers can always pass `Svg` directly for uncommon icons.
    private static SvgIcon MapName(string? name) => name switch
    {
        null or "" => Lucide.Circle,
        "Accessibility" => Lucide.Accessibility,
        "Activity" => Lucide.Activity,
        "AlertCircle" or "CircleAlert" => Lucide.CircleAlert,
        "AlertTriangle" or "TriangleAlert" => Lucide.TriangleAlert,
        "AlignCenter" => Lucide.AlignCenterHorizontal,
        "AlignLeft" => Lucide.AlignStartHorizontal,
        "AlignRight" => Lucide.AlignEndHorizontal,
        "Apple" => Lucide.Apple,
        "Archive" => Lucide.Archive,
        "ArrowDown" => Lucide.ArrowDown,
        "ArrowLeft" => Lucide.ArrowLeft,
        "ArrowRight" => Lucide.ArrowRight,
        "ArrowUp" => Lucide.ArrowUp,
        "ArrowUpRight" => Lucide.ArrowUpRight,
        "AtSign" => Lucide.AtSign,
        "BadgeCheck" => Lucide.BadgeCheck,
        "BarChart3" or "ChartBar" => Lucide.ChartBar,
        "Bell" => Lucide.Bell,
        "BellOff" => Lucide.BellOff,
        "Bold" => Lucide.Bold,
        "Bookmark" => Lucide.Bookmark,
        "Box" => Lucide.Box,
        "Calendar" => Lucide.Calendar,
        "CalendarDays" => Lucide.CalendarDays,
        "Camera" => Lucide.Camera,
        "Check" => Lucide.Check,
        "CheckCheck" => Lucide.CheckCheck,
        "CheckCircle2" or "CircleCheck" => Lucide.CircleCheck,
        "CheckSquare" => Lucide.SquareCheck,
        "ChevronDown" => Lucide.ChevronDown,
        "ChevronLeft" => Lucide.ChevronLeft,
        "ChevronRight" => Lucide.ChevronRight,
        "ChevronUp" => Lucide.ChevronUp,
        "ChevronsUpDown" => Lucide.ChevronsUpDown,
        "Chrome" => Lucide.Globe,
        "Circle" => Lucide.Circle,
        "CircleDot" => Lucide.CircleDot,
        "Clipboard" => Lucide.Clipboard,
        "Clock" => Lucide.Clock,
        "Code" => Lucide.Code,
        "Copy" => Lucide.Copy,
        "CreditCard" => Lucide.CreditCard,
        "DollarSign" => Lucide.DollarSign,
        "Download" => Lucide.Download,
        "Edit" or "Pencil" => Lucide.Pencil,
        "Ellipsis" => Lucide.Ellipsis,
        "ExternalLink" => Lucide.ExternalLink,
        "Eye" => Lucide.Eye,
        "EyeOff" => Lucide.EyeOff,
        "FileEdit" => Lucide.FilePen,
        "FileText" => Lucide.FileText,
        "Filter" => Lucide.Funnel,
        "Flag" => Lucide.Flag,
        "Folder" => Lucide.Folder,
        "FolderOpen" => Lucide.FolderOpen,
        "Github" => Lucide.Github,
        "Globe" => Lucide.Globe,
        "Heading1" => Lucide.Heading1,
        "Heading2" => Lucide.Heading2,
        "Heading3" => Lucide.Heading3,
        "Heart" => Lucide.Heart,
        "Home" or "House" => Lucide.House,
        "Image" => Lucide.Image,
        "Inbox" => Lucide.Inbox,
        "Info" => Lucide.Info,
        "Italic" => Lucide.Italic,
        "LayoutDashboard" => Lucide.LayoutDashboard,
        "LayoutGrid" => Lucide.LayoutGrid,
        "LineChart" => Lucide.ChartLine,
        "Link" => Lucide.Link,
        "Link2Off" or "Unlink" => Lucide.Link2Off,
        "List" => Lucide.List,
        "ListOrdered" => Lucide.ListOrdered,
        "Loader" => Lucide.Loader,
        "Lock" => Lucide.Lock,
        "LogIn" => Lucide.LogIn,
        "LogOut" => Lucide.LogOut,
        "Mail" => Lucide.Mail,
        "MapPin" => Lucide.MapPin,
        "Menu" => Lucide.Menu,
        "MessageCircle" => Lucide.MessageCircle,
        "MessageSquare" => Lucide.MessageSquare,
        "Mic" => Lucide.Mic,
        "Minus" => Lucide.Minus,
        "Moon" => Lucide.Moon,
        "MoreHorizontal" => Lucide.Ellipsis,
        "MousePointerClick" => Lucide.MousePointerClick,
        "Music" => Lucide.Music,
        "Package" => Lucide.Package,
        "Palette" => Lucide.Palette,
        "Paperclip" => Lucide.Paperclip,
        "Pause" => Lucide.Pause,
        "Phone" => Lucide.Phone,
        "PieChart" => Lucide.ChartPie,
        "Pilcrow" => Lucide.Pilcrow,
        "Pin" => Lucide.Pin,
        "Play" => Lucide.Play,
        "Plus" => Lucide.Plus,
        "Quote" => Lucide.Quote,
        "Redo" => Lucide.Redo,
        "RefreshCw" => Lucide.RefreshCw,
        "RemoveFormatting" => Lucide.RemoveFormatting,
        "Search" => Lucide.Search,
        "Send" => Lucide.Send,
        "Settings" => Lucide.Settings,
        "Share" or "Share2" => Lucide.Share2,
        "Shield" => Lucide.Shield,
        "ShieldAlert" => Lucide.ShieldAlert,
        "ShieldCheck" => Lucide.ShieldCheck,
        "ShoppingBag" => Lucide.ShoppingBag,
        "ShoppingCart" => Lucide.ShoppingCart,
        "SkipBack" => Lucide.SkipBack,
        "SkipForward" => Lucide.SkipForward,
        "SlidersHorizontal" => Lucide.SlidersHorizontal,
        "Smile" => Lucide.Smile,
        "SquareCode" => Lucide.SquareCode,
        "SquarePen" => Lucide.SquarePen,
        "Star" => Lucide.Star,
        "Strikethrough" => Lucide.Strikethrough,
        "Sun" => Lucide.Sun,
        "Tag" => Lucide.Tag,
        "Trash" or "Trash2" => Lucide.Trash2,
        "TrendingDown" => Lucide.TrendingDown,
        "TrendingUp" => Lucide.TrendingUp,
        "Truck" => Lucide.Truck,
        "Underline" => Lucide.Underline,
        "Undo" => Lucide.Undo,
        "Upload" => Lucide.Upload,
        "User" => Lucide.User,
        "UserPlus" => Lucide.UserPlus,
        "Users" => Lucide.Users,
        "Video" => Lucide.Video,
        "Volume2" => Lucide.Volume2,
        "Wallet" => Lucide.Wallet,
        "X" => Lucide.X,
        "Zap" => Lucide.Zap,
        _ => Lucide.Circle,
    };

    public enum IconSize { Xs, Sm, Md, Lg, Xl }
}
