using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PXP.Crawler.API.Designers;
using PXP.Crawler.API.Designers.Forms;

namespace PXP.Crawler.API.Model
{
    public class NodeContainer : Node
    {
        internal NodeContainerDesigner nodeDesigner;
        private Control cont;
        protected internal Padding padd = new Padding(4);

        public NodeContainer(Program program) : base(program)
        {
            nodeForm = new NodeForm(this);            
        }

        [Browsable(false)]
        public Control Control
        {
            get
            {
                return cont;
            }
            set
            {
                cont = value;
                if (cont != null)
                {
                    cont.Dock = DockStyle.Fill;
                    if (nodeDesigner != null)
                    {
                        nodeDesigner.ContainerControl.DesignerContainer.Controls.Add(cont);
                    }
                    else
                    {
                        nodeForm.Controls.Add(cont);                        
                    }
                }
            }
        }

        public override void CreateDesigner()
        {
            nodeDesigner = new NodeContainerDesigner(this);
            designer = nodeDesigner;
            nodeDesigner.Control.BackColor = Color.DarkOliveGreen;
            nodeDesigner.ContainerControl.ContainerPadding = padd;            

            if (cont != null)
            {
                nodeForm.Controls.Remove(cont);
                nodeDesigner.ContainerControl.DesignerContainer.Controls.Add(cont);
            }
        }


        public override void DestroyDesigner()
        {
            base.DestroyDesigner();
            if (cont != null)
                nodeForm.Controls.Add(cont);
        }

    }
}
