using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PXP.Crawler.API.Model;
using PXP.Crawler.API.Plugins.Operators;

namespace PXP.Crawler.API.Plugins.Utils
{
    [NodeInfo("Toggle", typeof(ToggleNode), Category = "Utils", Description = "Add two integers...",
        DefaultWidth = 80, DefaultHeight = 40, LockSize = true)]
    public class ToggleNode : ValueOperatorNodeBase<bool>
    {
        private bool toggleState = false;

        public ToggleNode(Program program) : base(program)
        {
        }

        public override void CreateDesigner()
        {
            base.CreateDesigner();
            designer.Control.BackColor = Color.Indigo;
        }

        protected internal override bool ComputeResult()
        {
            if (cvalue)
            {
                toggleState = !toggleState;
                cvalue = false;
            }

            return toggleState;
        }

        [NodePropertyPin(NodePinDirection.Input)]
        public bool Set
        {
            get { return false; }
            set
            {
                if (value)
                {
                    if (!result)
                    {
                        result = true;
                        NotifyPropertyChange("Result");
                    }
                }
            }
        }

        [NodePropertyPin(NodePinDirection.Input)]
        public bool Reset
        {
            get { return false; }
            set
            {
                if (value)
                {
                    if (result)
                    {
                        result = false;
                        NotifyPropertyChange("Result");
                    }
                }
            }
        }
    }
}
