using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;

namespace DashBoard.Controls;

/// <summary>
/// Interaction logic for DeviceInfoPlot.xaml
/// </summary>
public partial class DeviceInfoPlot : UserControl
{
    public DeviceInfoPlot()
    {
        InitializeComponent();
    }

    public DeviceData_VM DeviceData
    {
        get { return (DeviceData_VM)GetValue(DeviceDataProperty); }
        set { SetValue(DeviceDataProperty, value); }
    }

    public static readonly DependencyProperty DeviceDataProperty =
        DependencyProperty.Register("DeviceData", typeof(DeviceData_VM), typeof(DeviceInfoPlot), new PropertyMetadata(default));

    public DeviceInfo_VM DeviceInfo
    {
        get { return (DeviceInfo_VM)GetValue(DeviceInfoProperty); }
        set { SetValue(DeviceInfoProperty, value); }
    }

    public static readonly DependencyProperty DeviceInfoProperty =
        DependencyProperty.Register("DeviceInfo", typeof(DeviceInfo_VM), typeof(DeviceInfoPlot), new PropertyMetadata(default));


    public ICommand AlarmCommand
    {
        get { return (ICommand)GetValue(AlarmCommandProperty); }
        set { SetValue(AlarmCommandProperty, value); }
    }

    public static readonly DependencyProperty AlarmCommandProperty =
        DependencyProperty.Register("AlarmCommand", typeof(ICommand), typeof(DeviceInfoPlot), new PropertyMetadata(default));
}

public class NumberEnableConverter : IValueConverter
{
    public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is not int count)
            return default;

        return count switch
        {
            0 => false,
            _ => true
        };
    }

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

public class NumberBrushConverter : IValueConverter
{
    public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is not int count)
            return default;

        return count switch
        {
            0 => Application.Current.Resources["DisableColor"],
            _ => Application.Current.Resources["EmergencyColor"]
        };
    }

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