using InABox.Core;
using Syncfusion.Windows.Shared;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace InABox.DynamicGrid
{
    public class DFDoubleControl : DynamicFormFieldControl<DFLayoutDoubleField, DFLayoutDoubleFieldProperties, double, double?>
    {
        private DoubleTextBox Double = null!; // late-initialising

        protected override FrameworkElement Create()
        {
            Double = new DoubleTextBox();
            Double.Value = Field.Properties.Default;
            Double.HorizontalContentAlignment = HorizontalAlignment.Center;
            Double.VerticalContentAlignment = VerticalAlignment.Center;
            Double.VerticalAlignment = VerticalAlignment.Stretch;
            Double.ValueChanged += (sender, e) => ChangeField();
            Double.IsScrollingOnCircle = false;
            return Double;
        }

        public override void SetSerializedValue(double? value)
        {
            Double.Value = value;
        }

        public override double? GetSerializedValue()
        {
            return Double.Value ?? 0.0;
        }

        public override double GetValue()
        {
            return Double.Value ?? 0.0;
        }

        public override void SetValue(double value)
        {
            Double.Value = value;
        }
        protected override bool IsEmpty() => Double.Value == null;
    }
}