using System.Globalization;

namespace Blahblah.FlowerApp;

class VisibleIfNotNullConverter : IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is string s)
        {
            return !string.IsNullOrEmpty(s);
        }
        return value != null;
    }

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


class DateTimeStringConverter : IValueConverter
{
    public string Format { get; init; } = "MM/dd HH:mm:ss";

    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is long time)
        {
            var date = DateTimeOffset.FromUnixTimeMilliseconds(time);
            return date.ToLocalTime().ToString(Format);
        }
        return value;
    }

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