using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LSFE.MobApp.Converters
{
    public class InitialsConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string name && !string.IsNullOrWhiteSpace(name))
            {
                var words = name.Split(' ', StringSplitOptions.RemoveEmptyEntries);
                if (words.Length >= 2)
                {
                    return $"{words[0].First()}{words[1].First()}".ToUpper();
                }
                else if (words.Length == 1)
                {
                    return words[0].Length >= 2 ?
                        words[0].Substring(0, 2).ToUpper() :
                        words[0].First().ToString().ToUpper();
                }
            }
            return "DR";
        }

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