using System.Globalization;
using Avalonia.Data.Converters;
using Avalonia.Media;
namespace DodoSSH.Client.App.Views;
///
/// Turns a host card's MonogramHue string into the background or foreground brush the mock pairs it
/// with.
///
///
///
/// The four pairs are the design's own and are not in Palette.axaml: that file is another wave's, and
/// none of the shared palette's existing keys is this hue ramp — a monogram's colour is a property of the
/// four-way hash in HostRowViewModel.MonogramHue, not a fact the rest of the theme has any use for.
/// Held here, beside the one screen that reads it, rather than invented as four new shared resources for a
/// single card.
///
///
/// Two instances rather than one converter taking a "which half" parameter, so the markup names each with a
/// StaticResource-shaped reference instead of a converter parameter that means nothing without
/// reading this file.
///
///
internal sealed class MonogramBrushConverter(bool background) : IValueConverter
{
/// The fill behind the two letters.
internal static MonogramBrushConverter Background { get; } = new(background: true);
/// The colour of the two letters themselves.
internal static MonogramBrushConverter Foreground { get; } = new(background: false);
/// violet, green, amber, gray — the four pairs the mock assigns a monogram.
private static readonly Dictionary Pairs = new(
StringComparer.Ordinal)
{
["violet"] = ("#241C4F", "#A78BFA"),
["green"] = ("#103A2F", "#34D399"),
["amber"] = ("#423211", "#F5B942"),
["gray"] = ("#1E1E2C", "#9C9EB4"),
};
///
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
var pair = value is string hue && Pairs.TryGetValue(hue, out var found) ? found : Pairs["gray"];
return new SolidColorBrush(Color.Parse(background ? pair.Background : pair.Foreground));
}
///
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) =>
throw new NotSupportedException("The monogram hue is read-only.");
}