Files
LanMountainDesktop/LanMountainDesktop/ComponentSystem/ComponentCategoryIconResolver.cs
2026-05-25 09:32:58 +08:00

50 lines
1.3 KiB
C#

using System.Collections.Generic;
using FluentIcons.Common;
namespace LanMountainDesktop.ComponentSystem;
public static class ComponentCategoryIconResolver
{
public static Icon ResolveCategoryIcon(
string categoryId,
IEnumerable<DesktopComponentDefinition> categoryComponents)
{
if (string.Equals(categoryId, "all", StringComparison.OrdinalIgnoreCase))
{
return Icon.Apps;
}
var icon = categoryId.ToLowerInvariant() switch
{
"clock" => Icon.Clock,
"date" => Icon.Calendar,
"weather" => Icon.WeatherSunny,
"board" => Icon.Edit,
"media" => Icon.Play,
"info" => Icon.News,
"calculator" => Icon.Calculator,
"study" => Icon.Book,
"file" => Icon.Folder,
_ => (Icon?)null
};
if (icon.HasValue)
{
return icon.Value;
}
var firstComponent = categoryComponents.FirstOrDefault();
if (firstComponent is null || string.IsNullOrWhiteSpace(firstComponent.IconKey))
{
return Icon.Apps;
}
if (Enum.TryParse<Icon>(firstComponent.IconKey, ignoreCase: true, out var resolvedIcon))
{
return resolvedIcon;
}
return Icon.Apps;
}
}