using System.Globalization;
using System.Windows;
using System.Windows.Data;
using NexusShell.Models;

namespace NexusShell.Converters;

public sealed class NexusSettingsSectionVisibilityConverter : IValueConverter
{
    public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is not NexusSettingsSection selected || parameter is not string raw)
        {
            return Visibility.Collapsed;
        }

        return Enum.TryParse<NexusSettingsSection>(raw, ignoreCase: true, out var section) &&
               selected == section
            ? Visibility.Visible
            : Visibility.Collapsed;
    }

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

public sealed class NexusSettingsNavActiveConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object? parameter, CultureInfo culture)
    {
        if (values.Length < 2 ||
            values[0] is not NexusSettingsSection selected ||
            values[1] is not NexusSettingsSection item)
        {
            return false;
        }

        return selected == item;
    }

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