using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PXP.Crawler.API.Designers.Controls;
using PXP.Crawler.API.Model;
using PXP.Crawler.API.Utils;

namespace PXP.Crawler.API.Plugins.Values
{
    [NodeInfo("Text", typeof(TextNodeBase), Category = "Values", Description = "Text Value", DefaultWidth = 270, DefaultHeight = 65)]
    public class TextNodeBase : StringNodeBase
    {
        public TextNodeBase(Program program) : base(program)
        {
        }


        public override void CreateDesigner()
        {
            base.CreateDesigner();
            NodeDesignerControl ndCont = (NodeDesignerControl)designer.Control;
            ndCont.TitlePositionAdjust = new Point(-6, -3);
        }

        [NodeSerializeProperty]
        public bool WordWrap
        {
            get
            {
                return valControl.valueMemoEdit.Properties.WordWrap;
            }
            set
            {
                valControl.valueMemoEdit.Properties.WordWrap = value;
            }
        }

        [NodePropertyPin]
        public new string Value
        {
            get
            {
                return valControl.valueMemoEdit.Text;
            }
            set
            {
                if (valControl.valueMemoEdit.Text != value)
                {
                    valControl.valueMemoEdit.Text = value;
                }
                NotifyPropertyChange("Value");
            }
        }

        protected override void InitValueControl()
        {
            valControl.valueTextEdit.Visible = false;
            valControl.valueMemoEdit.Visible = true;
            valControl.valueMemoEdit.Validated += valueMemoEdit_Validated;
        }

        void valueMemoEdit_Validated(object sender, EventArgs e)
        {
            Value = valControl.valueMemoEdit.Text;
        }
    }
}
