using AIStudio.Provider; using AIStudio.Settings; using Microsoft.AspNetCore.Components; namespace AIStudio.Components; /// /// Shows the icon of a provider. /// /// /// The icon is rendered as an image instead of inline SVG. That way the browser treats the icon as /// a standalone, script-less document, which matters for the custom icons a configuration plugin /// may supply. /// public partial class ProviderIcon : ComponentBase { /// /// The configured provider whose icon should be shown. Takes precedence over ProviderType. /// [Parameter] public AIStudio.Settings.Provider? ProviderSettings { get; set; } /// /// The LLM provider whose icon should be shown when no ProviderSettings was given. /// [Parameter] public LLMProviders ProviderType { get; set; } = LLMProviders.NONE; /// /// The validated custom icon supplied by a configuration plugin. /// [Parameter] public string CustomIconDataUrl { get; set; } = string.Empty; /// /// Additional CSS class for the icon. /// [Parameter] public string Class { get; set; } = string.Empty; /// /// Additional inline style for the icon. /// [Parameter] public string Style { get; set; } = string.Empty; [Inject] private SettingsManager SettingsManager { get; init; } = null!; /// /// The provider-icon class carries the sizing from app.css. Callers add to it instead of /// replacing it, so an icon cannot lose its size by setting a class of its own. /// private string CssClass => $"provider-icon {this.Class}".TrimEnd(); private string IconUrl => this.ProviderSettings?.GetIconUrl(this.SettingsManager.IsDarkMode) ?? this.ProviderType.GetIconUrl(this.SettingsManager.IsDarkMode, this.CustomIconDataUrl); }