using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.UIElements.Experimental;

public class UIConverters
{
#if UNITY_EDITOR
    [InitializeOnLoadMethod]
#else
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
#endif
    public static void InitConverters(){
        var group = new ConverterGroup("Normalized to Percent");
        group.AddConverter<float, StyleLength >((ref float input) => Length.Percent(input * 100));
        ConverterGroups.RegisterConverterGroup(group);
        
        var invert = new ConverterGroup("Normalized to Percent (Inverted)");
        invert.AddConverter<float, StyleLength>((ref float input) => Length.Percent(-input * 100f));
        ConverterGroups.RegisterConverterGroup(invert);

        var boolColorConverter = new ConverterGroup("Bool to Color");
        boolColorConverter.AddConverter<bool, StyleColor>(((ref bool input) => boolToColor(input)));
        ConverterGroups.RegisterConverterGroup(boolColorConverter);
        
        return;
        
        StyleColor boolToColor(bool value){
            if (value == true) {
                return new Color(113, 113, 113);
            }

            return new Color(73, 132, 99);
        }
        
        
    }
}
