using System;
using System.Windows.Controls;
using System.Windows.Media;
using InABox.Core;

namespace InABox.DynamicGrid;

public class StringValueNode : ValueNode {

    private TextBox Editor;

    public override object? Value {
        get => Editor.Text;
        set
        {
            if (value is string || value?.GetType().IsOrdinal() == true || value is DateTime || value is bool || value is Enum)
                Editor.Text = value.ToString() ?? "";
            else
                Editor.Text = "";
        } 
    }
    
    public override bool IsEnabled
    {
        get => Editor.IsEnabled;
        set
        {
            Editor.IsEnabled = value;
            Editor.IsReadOnly = !value;
        }
    }

    public StringValueNode()
    {
        Editor = new TextBox
        {
            VerticalAlignment = System.Windows.VerticalAlignment.Stretch,
            VerticalContentAlignment = System.Windows.VerticalAlignment.Center,
            Background = new SolidColorBrush(Colors.LightYellow)
        };
        Content = Editor;
    }

}