using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.Utils;
using PXP.Crawler.API.Model;

namespace PXP.Crawler.API.Plugins.Values
{
    [NodeInfo("Number (Float)", typeof(NumberFloatNode), Category = "Values", Description = "Integer Value", 
        DefaultWidth = 150, DefaultHeight = 60, LockHeight = true)]
    public class NumberFloatNode : NumberNodeBase<int>
    {
        private int cvalue = 0;

        public NumberFloatNode(Program program)
            : base(program)
        {

        }

        protected override void InitValueControl()
        {
            base.InitValueControl();

            valControl.valueSpinEdit.Properties.IsFloatValue = true;
            valControl.valueSpinEdit.Properties.DisplayFormat.FormatType = FormatType.Numeric;
            valControl.valueSpinEdit.Properties.DisplayFormat.FormatString = "n4";
            valControl.valueSpinEdit.Properties.EditFormat.FormatType = FormatType.Numeric;
            valControl.valueSpinEdit.Properties.EditFormat.FormatString = "n4";
        }

        protected override void OnValueChanged()
        {
            base.OnValueChanged();
            Value = Convert.ToInt32(valControl.valueSpinEdit.Value);
        }

        [NodePropertyPin]
        public override int Value
        {
            get
            {
                return cvalue;
            }
            set
            {
                if (cvalue != value)
                {
                    cvalue = value;
                    valControl.valueSpinEdit.Value = cvalue;
                    NotifyPropertyChange("Value");
                }
            }
        }
    }
}
