using System.Globalization;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Data.Converters;
using Avalonia.Media;
namespace AvParser.UI.Converters;
/// Small one-way converters used by the views.
public static class AppConverters
{
/// Collection counts to a boolean, for showing a panel only when it has content.
public static readonly FuncValueConverter IsPositive = new(static count => count > 0);
/// Inverts a boolean, for enabling a control while a command is idle.
public static readonly FuncValueConverter Not = new(static value => !value);
/// Formats a 0..1 fraction as a whole-number percentage.
public static readonly FuncValueConverter Percent = new(static value =>
value.ToString("P0", CultureInfo.CurrentCulture)
);
///
/// Resolves an icon key from Styles/Icons.axaml to the geometry it names.
///
///
/// Lets view models refer to icons by a plain string instead of holding
/// instances, which keeps them trivially constructible in tests.
///
public static readonly FuncValueConverter IconKeyToGeometry = new(static key =>
key is not null && Application.Current is { } app && app.TryFindResource(key, out var resource)
? resource as Geometry
: null
);
}