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

namespace MMEA.Converters
{
    /// <summary>
    ///     Converter to change bool to a opacity
    /// </summary>
    public class BoolToOpacityConverter : IValueConverter, IMarkupExtension
    {
        /// <inheritdoc />
        public object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }

        /// <inheritdoc />
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var hasRead = (bool) value;
            if (hasRead)
                return 0.4;
            return 1;
        }

        /// <inheritdoc />
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}