using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using PXP.Crawler.API.Model;
using PXP.Crawler.API.Model.Core;

namespace PXP.Crawler.API.Designers.Property.Forms
{
    public partial class ProgramSelectXtraForm : DevExpress.XtraEditors.XtraForm
    {
        private ProgramNode prNode;
        public ProjectItem selectedItem;

        public ProgramSelectXtraForm()
        {
            InitializeComponent();
        }

        public ProgramSelectXtraForm(ProgramNode prNode)
        {
            this.prNode = prNode;
            InitializeComponent();


            projectDesignerControl.Project = prNode.Program.Project;}

        private void projectDesignerControl_SelectionChanged(object sender, EventArgs e)
        {
            selectedItem = projectDesignerControl.SelectedItem;
            propertyGridControl.SelectedObject = selectedItem;
            if (selectedItem.Type == ProjectItem.ProjectItemType.Program)
            {

                if (prNode.program.id != selectedItem.projectObjectID)
                {
                    okSimpleButton.Enabled = true;
                }
                else
                {
                    //XtraMessageBox.Show("Program can not host it self...", "Error Recursion", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                okSimpleButton.Enabled = false;
            }
        }

        private void okSimpleButton_Click(object sender, EventArgs e)
        {
            selectedItem = projectDesignerControl.SelectedItem;            
        }

        private void projectDesignerControl_OpenItem(object sender, ProjectItemEventArgs e)
        {
            if (e.Item.type == ProjectItem.ProjectItemType.Program)
            {
                selectedItem = e.Item;
                okSimpleButton.PerformClick();
            }
        }

        private void ProgramSelectXtraForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                CancelButton.PerformClick();
            }
        }
    }
}