using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
using ControlzEx.Theming;

namespace InABox.WPF.Themes
{

    // public enum ThemeBase
    // {
    //     Light,
    //     Dark
    // }
    
    public static class ThemeManager
    {

        //private static Theme? _theme;
        
        public static event PropertyChangedEventHandler? StaticPropertyChanged;
        
        private static System.Windows.Media.Color _baseColor = Colors.DarkGreen;
        public static System.Windows.Media.Color BaseColor
        {
            get => _baseColor;
            set
            {
                _baseColor = value;
                
                //_theme = RuntimeThemeGenerator.Current.GenerateRuntimeTheme("Light", _baseColor, false);

                Notify();
            }
        }
        
        private static void Notify()
        {
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(WorkspaceBackgroundColor)));
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(WorkspaceBackgroundBrush)));

            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(WorkspaceForegroundColor)));
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(WorkspaceForegroundBrush)));

            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(BackstageBackgroundColor)));
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(BackstageBackgroundBrush)));

            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(BackstageForegroundColor)));
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(BackstageForegroundBrush)));

            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(SelectedTabItemBackgroundColor)));
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(SelectedTabItemBackgroundBrush)));
            
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(SelectedTabItemForegroundColor)));
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(SelectedTabItemForegroundBrush)));
            
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(SelectionBackgroundColor)));
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(SelectionBackgroundBrush)));
            
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(SelectionForegroundColor)));
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(SelectionForegroundBrush)));
            
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(FilterBackgroundColor)));
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(FilterBackgroundBrush)));
            
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(FilterForegroundColor)));
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(FilterForegroundBrush)));
            
        }

        public static System.Windows.Media.Color WorkspaceBackgroundColor => Colors.White;
            //_baseColor
            //.AdjustHue(0)
            //.AdjustSaturation(-50)
            //.AdjustLightness(95);
        public static System.Windows.Media.Color WorkspaceForegroundColor => WorkspaceBackgroundColor.GetForegroundColor(160);

        public static System.Windows.Media.Color BackstageBackgroundColor => _baseColor
            .AdjustHue(0)
            .AdjustSaturation(0) //(-20)
            .AdjustLightness(0); //(50);
        public static System.Windows.Media.Color BackstageForegroundColor => BackstageBackgroundColor.GetForegroundColor(160);
        
        public static System.Windows.Media.Color SelectedTabItemBackgroundColor => _baseColor
            .AdjustHue(-120)
            .AdjustSaturation(-20)
            .AdjustLightness(20);
        public static System.Windows.Media.Color SelectedTabItemForegroundColor => SelectedTabItemBackgroundColor.GetForegroundColor(160);

        public static System.Windows.Media.Color SelectionBackgroundColor => _baseColor
            .AdjustHue(0)
            .AdjustSaturation(-50)
            .AdjustLightness(20);
        public static System.Windows.Media.Color SelectionForegroundColor => SelectionBackgroundColor.GetForegroundColor(160);

        public static System.Windows.Media.Color FilterBackgroundColor => _baseColor
            .AdjustHue(0)
            .AdjustSaturation(-50)
            .AdjustLightness(90); //(80);
        public static System.Windows.Media.Color FilterForegroundColor => FilterBackgroundColor.GetForegroundColor(160);
        
        public static SolidColorBrush WorkspaceBackgroundBrush => new SolidColorBrush(WorkspaceBackgroundColor);
        public static SolidColorBrush WorkspaceForegroundBrush => new SolidColorBrush(WorkspaceForegroundColor);
        
        public static SolidColorBrush BackstageBackgroundBrush => new SolidColorBrush(BackstageBackgroundColor);
        public static SolidColorBrush BackstageForegroundBrush => new SolidColorBrush(BackstageForegroundColor);
        
        public static SolidColorBrush SelectedTabItemBackgroundBrush => new SolidColorBrush(SelectedTabItemBackgroundColor);
        public static SolidColorBrush SelectedTabItemForegroundBrush => new SolidColorBrush(SelectedTabItemForegroundColor);
        
        public static SolidColorBrush SelectionBackgroundBrush => new SolidColorBrush(SelectionBackgroundColor);
        public static SolidColorBrush SelectionForegroundBrush => new SolidColorBrush(SelectionForegroundColor);
        
        public static SolidColorBrush FilterBackgroundBrush => new SolidColorBrush(FilterBackgroundColor);
        public static SolidColorBrush FilterForegroundBrush => new SolidColorBrush(FilterForegroundColor);
        
    }
}