using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PXP.Crawler.API.Model;
using PXP.Crawler.API.Plugins.Properties;

namespace PXP.Crawler.API.Plugins.Net.Chrome
{
    [NodeInfo("Get Attribute", typeof(ChromeElementGetAttribute), Category = "Chrome", Description = "Get element attribute...")]
    [NodeInfo.NodeInfoIcon(typeof(Resources), "ElementAttribute")]
    public class ChromeElementGetAttribute : ChromeElementNodeBase
    {
        private string attName = "";
        private string val = "";


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

        protected override void OnElementChanged()
        {
            base.OnElementChanged();
            if (hasElement)
            {
                if (attName.Length > 0)
                    Value = element.GetAttribute(attName);
            }
            else
            {
                Value = "";
            }
        }

        [NodeSerializeProperty]
        [Browsable(true)]
        public string AttributeName
        {
            get
            {
                return attName;
            }
            set
            {
                attName = value;
                OnElementChanged();
            }
        }

        [NodePropertyPin(NodePinDirection.Output)]
        public string Value
        {
            get
            {
                return val;
            }
            set
            {
                val = value;
                NotifyPropertyChange("Value");
            }
        }
    }
}
