using System.Collections;
using System.Linq;
using System.Windows;

namespace InABox.WPF;

public class EnumerableToVisibilityConverter : AbstractConverter<IEnumerable?, Visibility>
{
    
    public Visibility Empty { get; set; } = Visibility.Collapsed;
    public Visibility NotEmpty { get; set; } = Visibility.Visible;
    
    public override Visibility Convert(IEnumerable? value)
    {
        if (value == null)
            return Empty;
        var enumerable = value as object[] ?? value.Cast<object>().ToArray();
        if (!enumerable.GetEnumerator().MoveNext())
            return Empty;
        return NotEmpty;
    }
}