using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using JuliusSweetland.OptiKey.Enums;

namespace JuliusSweetland.OptiKey.UI.ValueConverters
{
    public class MinimiseAndDockPositionToSymbolOrientation : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values.Length == 2
                && values[0] != DependencyProperty.UnsetValue
                && values[1] != DependencyProperty.UnsetValue)
            {
                var minimisedPosition = (MinimisedEdges)values[0];
                var dockPosition = (DockEdges)values[1];

                switch (minimisedPosition == MinimisedEdges.SameAsDockedPosition ? dockPosition.ToMinimisedEdge() : minimisedPosition)
                {
                    case MinimisedEdges.Right:
                        return SymbolOrientations.Right;

                    case MinimisedEdges.Bottom:
                        return SymbolOrientations.Bottom;

                    case MinimisedEdges.Left:
                        return SymbolOrientations.Left;

                    default: //case MinimisedEdges.Top:
                        return SymbolOrientations.Top;
                }
            }
            
            return SymbolOrientations.Top; //Default
        }

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