namespace Htmx.ApiDemo.Templates.Components;
///
/// shadcn-style Avatar component. Shows an image or falls back to initials.
/// Size: sm (h-8 w-8) | default (h-10 w-10) | lg (h-14 w-14) | xl (h-20 w-20)
///
public sealed class Avatar : AvatarBase
{
private static readonly Dictionary Sizes = new()
{
["sm"] = "h-8 w-8",
["default"] = "h-10 w-10",
["lg"] = "h-14 w-14",
["xl"] = "h-20 w-20",
};
private readonly byte[] _sizeClassesData;
private readonly byte[] _contentData;
public Avatar(string fallback, string? src = null, string size = "default")
{
_sizeClassesData = Sizes.GetValueOrDefault(size, Sizes["default"]).ToUtf8Bytes();
_contentData = !string.IsNullOrEmpty(src)
? $"""
""".ToUtf8Bytes()
: $"""{fallback}""".ToUtf8Bytes();
}
protected override void RenderSizeClasses(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_sizeClassesData);
protected override void RenderContent(HtmxRenderContext ctx) => ctx.Writer.WriteUtf8(_contentData);
}