using System;
using System.Globalization;
using Xamarin.Forms;

namespace InABox.Mobile
{
    public class BoolToGridLengthConverter : IValueConverter
    {
        public GridLength TrueValue { get; set; }
        public GridLength FalseValue { get; set; }
        
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if ((value is bool bvalue) && bvalue)
                return TrueValue;
            return FalseValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is GridLength length)
                return length.Equals(TrueValue);
            return false;
        }
    }
}