using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace ClaudeDo.Installer.Core;

/// <summary>
/// Multi-value converter: compares the page's index with the current page index
/// to determine step indicator styling.
/// </summary>
public sealed class StepActiveConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        if (values.Length < 2 ||
            values[0] is not IInstallerPage page ||
            values[1] is not IInstallerPage currentPage)
            return DependencyProperty.UnsetValue;

        var isActive = ReferenceEquals(page, currentPage);

        var key = parameter?.ToString() switch
        {
            "Background" => isActive ? "AccentBrush" : "WindowBgBrush",
            "Foreground" => isActive ? "TextPrimaryBrush" : "TextMutedBrush",
            "BorderBrush" => isActive ? "AccentBrush" : "BorderSubtleBrush",
            _ => null
        };

        if (key is null) return DependencyProperty.UnsetValue;
        return Application.Current.Resources[key] as SolidColorBrush ?? DependencyProperty.UnsetValue;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        => throw new NotSupportedException();
}
