using System.Windows.Controls;

namespace InABox.DynamicGrid;

public class BooleanValueNode : ValueNode {

    private ComboBox Editor;

    public override object? Value {
        get => (string)Editor.SelectedItem == "True";
        set {
            if(value is bool b)
            {
                Editor.SelectedItem = b ? "True" : "False";
            }
            else
            {
                Editor.SelectedItem = "False";
            }
        }
    }
    
    public override bool IsEnabled
    {
        get => Editor.IsEnabled;
        set
        {
            Editor.IsEnabled = value;
            Editor.IsReadOnly = !value;
        }
    }

    public BooleanValueNode()
    {
        Editor = new ComboBox
        {
            VerticalAlignment = System.Windows.VerticalAlignment.Stretch,
            VerticalContentAlignment = System.Windows.VerticalAlignment.Center
        };

        Editor.Items.Add("True");
        Editor.Items.Add("False");

        Content = Editor;
    }
}