using System;
using InABox.Core;
using Syncfusion.Windows.Shared;

namespace InABox.DynamicGrid;

public class IntegerValueNode : ValueNode {

    private IntegerTextBox Editor;

    public override object? Value {
        get => Editor.Value; 
        set {
            if (value?.GetType().IsOrdinal() == true)
                Editor.Value = Convert.ToInt64(value);
            else if (value is string str && long.TryParse(str, out var num))
                Editor.Value = num;
            else
                Editor.Value = 0;
        }
    }
    
            
    public override bool IsEnabled
    {
        get => Editor.IsEnabled;
        set
        {
            Editor.IsEnabled = value;
            Editor.IsReadOnly = !value;
        }
    }

    public IntegerValueNode()
    {
        Editor = new IntegerTextBox
        {
            VerticalAlignment = System.Windows.VerticalAlignment.Stretch,
            VerticalContentAlignment = System.Windows.VerticalAlignment.Center,
            HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
            HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center
        };
        Content = Editor;
    }

}