using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Forms;

namespace QC.QTMApplication;

public class CheckStateToNullableBooleanConverter : IValueConverter
{
	public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
	{
		bool? flag = null;
		if (value is CheckState checkState)
		{
			switch (checkState)
			{
			case CheckState.Checked:
				flag = true;
				break;
			case CheckState.Unchecked:
				flag = false;
				break;
			case CheckState.Indeterminate:
				flag = null;
				break;
			}
		}
		return flag;
	}

	public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
	{
		CheckState checkState = CheckState.Indeterminate;
		if (value is bool? flag)
		{
			checkState = ((!flag.HasValue) ? CheckState.Indeterminate : (flag.Value ? CheckState.Checked : CheckState.Unchecked));
		}
		return checkState;
	}
}
