using System.Globalization;
using Avalonia.Data.Converters;
using Avalonia.Media;
using ClaudeDo.Data.Models;

namespace ClaudeDo.Ui.Converters;

public sealed class WorktreeStateColorConverter : IValueConverter
{
    private static readonly ISolidColorBrush Active = new SolidColorBrush(Color.Parse("#42A5F5"));
    private static readonly ISolidColorBrush Merged = new SolidColorBrush(Color.Parse("#66BB6A"));
    private static readonly ISolidColorBrush Discarded = new SolidColorBrush(Color.Parse("#9E9E9E"));
    private static readonly ISolidColorBrush Kept = new SolidColorBrush(Color.Parse("#FFA726"));
    private static readonly ISolidColorBrush Default = new SolidColorBrush(Colors.Gray);

    public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
        value is WorktreeState state
            ? state switch
            {
                WorktreeState.Active    => Active,
                WorktreeState.Merged    => Merged,
                WorktreeState.Discarded => Discarded,
                WorktreeState.Kept      => Kept,
                _                       => Default,
            }
            : Default;

    public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
        => throw new NotSupportedException();
}
