using System.Globalization;

namespace BookReader.Converters;

public class ProgressToWidthConverter : IValueConverter
{
    public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is double progress)
        {
            var maxWidth = (double)Constants.UI.ProgressBarMaxWidth;
            if (parameter is string paramStr && double.TryParse(paramStr, out var max))
                maxWidth = max;
            return progress * maxWidth;
        }
        return 0;
    }

    public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}