using LiteDB;
using MegaRobo.Contract;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace MegaRobo.C00225155App.Converters
{
    public class StringToStatus1ColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string state)
            {
                if (state == "待机")
                {
                    return (Brush)new BrushConverter().ConvertFrom("#ccc7c7");
                }
                else if (state == "制冷状态")
                {
                    return (Brush)new BrushConverter().ConvertFrom("#1982d8");
                }
                else if (state == "制热状态")
                {
                    return (Brush)new BrushConverter().ConvertFrom("#ee7151");
                }
            }
            return Brushes.Transparent;
        }

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

    public class StringToCoolStateColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string coolstate)
            {
                if (coolstate == "正常")
                {
                    return (Brush)new BrushConverter().ConvertFrom("#28e847");
                }
                else if (coolstate == "传感器短路")
                {
                    return (Brush)new BrushConverter().ConvertFrom("#f22409");
                }
                else if (coolstate == "传感器开路")
                {
                    return (Brush)new BrushConverter().ConvertFrom("#f22409");
                }
            }
            return Brushes.Transparent;
        }

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

    public class StringToStatus2ColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string state)
            {
                if (state == "正常")
                {
                    return (Brush)new BrushConverter().ConvertFrom("#28e847");
                }
                else if (state == "低温报警")
                {
                    return (Brush)new BrushConverter().ConvertFrom("#f22409");
                }
                else if (state == "高温报警")
                {
                    return (Brush)new BrushConverter().ConvertFrom("#f22409");
                }
            }
            return Brushes.Transparent;
        }

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

    public class StringToMagneticStirRunColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string state)
            {
                if (state == "停止")
                {
                    return (Brush)new BrushConverter().ConvertFrom("#ccc7c7");
                }
                else if (state == "运行")
                {
                    return (Brush)new BrushConverter().ConvertFrom("#28e847");
                }
            }
            return Brushes.Transparent;
        }

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

    public class StringToRanmanColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string state)
            {
                if (state == "就绪")
                {
                    return (Brush)new BrushConverter().ConvertFrom("#ccc7c7");
                }
                else if (state == "运行中")
                {
                    return (Brush)new BrushConverter().ConvertFrom("#28e847");
                }
                else if (state == "故障")
                {
                    return (Brush)new BrushConverter().ConvertFrom("#f22409");
                }
                else if (state == "未初始化")
                {
                    return (Brush)new BrushConverter().ConvertFrom("#f22409");
                }
            }
            return Brushes.Transparent;
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class StirStateToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string stirstate)
            {
                if (stirstate == "停止")
                {
                    return Visibility.Hidden;
                }
                else if (stirstate == "运行")
                {
                    return Visibility.Visible;
                }
            }
            return Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is Visibility visibilityValue)
            {
                return visibilityValue == Visibility.Visible;
            }
            return false;
        }
    }

}
