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

namespace CtrEditor.FuncionesBase
{
    public class BooleanToDoubleConverter : IValueConverter
    {
        public double TrueValue { get; set; } = -1;
        public double FalseValue { get; set; } = 1;

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool boolValue)
            {
                return boolValue ? TrueValue : FalseValue;
            }
            return FalseValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is double doubleValue)
            {
                return Math.Abs(doubleValue - TrueValue) < double.Epsilon;
            }
            return false;
        }
    }
}
