using System.Globalization; namespace IronServices.Maui.Controls; /// /// Converts an integer to a boolean (true if greater than zero). /// public class IsGreaterThanZeroConverter : IValueConverter { public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) => value is int i && i > 0; public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException(); } /// /// Converts a string to a boolean (true if not null or empty). /// public class StringToBoolConverter : IValueConverter { public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) => !string.IsNullOrEmpty(value as string); public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException(); } /// /// Inverts a boolean value. /// public class InvertedBoolConverter : IValueConverter { public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) => value is bool b && !b; public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => value is bool b && !b; } /// /// Converts JourneyDisplayStatus or StepDisplayStatus to a Color. /// public class StatusToColorConverter : IValueConverter { public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { return value switch { JourneyDisplayStatus.InProgress => Colors.Blue, JourneyDisplayStatus.Completed => Colors.Green, JourneyDisplayStatus.Failed => Colors.Red, JourneyDisplayStatus.Abandoned => Colors.Gray, StepDisplayStatus.InProgress => Colors.Blue, StepDisplayStatus.Completed => Colors.Green, StepDisplayStatus.Failed => Colors.Red, StepDisplayStatus.Skipped => Colors.Gray, _ => Colors.Gray }; } public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException(); } /// /// Converts nesting level to a left margin for indentation. /// public class NestingLevelToMarginConverter : IValueConverter { public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is int level) return new Thickness(level * 20, 0, 0, 0); return new Thickness(0); } public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException(); } /// /// Converts JourneyViewMode to a boolean for visibility binding. /// Parameter should be the target mode (e.g., "Timeline", "Tree", "Flow"). /// public class ViewModeToVisibilityConverter : IValueConverter { public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is JourneyViewMode mode && parameter is string targetMode) { return mode.ToString().Equals(targetMode, StringComparison.OrdinalIgnoreCase); } return false; } public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException(); } /// /// Converts JourneyViewMode to a background color for tab-style buttons. /// Returns Primary color when selected, Transparent when not. /// public class ViewModeToBackgroundConverter : IValueConverter { public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is JourneyViewMode mode && parameter is string targetMode) { var isSelected = mode.ToString().Equals(targetMode, StringComparison.OrdinalIgnoreCase); return isSelected ? Color.FromArgb("#512BD4") : Colors.Transparent; } return Colors.Transparent; } public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException(); } /// /// Converts JourneyViewMode to a text color for tab-style buttons. /// Returns White when selected, Primary when not. /// public class ViewModeToTextColorConverter : IValueConverter { public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is JourneyViewMode mode && parameter is string targetMode) { var isSelected = mode.ToString().Equals(targetMode, StringComparison.OrdinalIgnoreCase); return isSelected ? Colors.White : Color.FromArgb("#512BD4"); } return Color.FromArgb("#512BD4"); } public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException(); } /// /// Converts a dictionary to a formatted string for display. /// public class DictionaryToStringConverter : IValueConverter { public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is Dictionary dict && dict.Count > 0) { return string.Join("\n", dict.Select(kvp => $"{kvp.Key}: {kvp.Value}")); } return "No data"; } public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException(); } /// /// Converts a collection count to visibility (visible if count > 0). /// public class CountToVisibilityConverter : IValueConverter { public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is int count) return count > 0; if (value is System.Collections.ICollection collection) return collection.Count > 0; return false; } public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException(); }