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

namespace InvExplorer
{
    /// <summary>
    /// Converts numbers into brushes
    /// </summary>
    public class NumberColorConverter : IValueConverter
    {
        public NumberColorConverter()
        {
            NegativeBrush = new SolidColorBrush(Color.FromArgb(0xff, 0xa0, 0, 0));
            PositiveBrush = new SolidColorBrush(Color.FromArgb(0xff, 0, 0x80, 0));
            ZeroBrush = new SolidColorBrush(Color.FromArgb(0xff, 0, 0, 0));
        }

        public Brush NegativeBrush { get; set; }
        public Brush PositiveBrush { get; set; }
        public Brush ZeroBrush { get; set; }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var dbl = (double)System.Convert.ChangeType(value, typeof(double), null);
            return 
                dbl < 0 ? NegativeBrush :
                dbl > 0 ? PositiveBrush :
                ZeroBrush;
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
