using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using PXP.Crawler.API.Designers.Property;
using PXP.Crawler.API.Designers.Property.Forms;
using PXP.Crawler.API.Model.Core;
using PXP.Crawler.API.Utils;

namespace PXP.Crawler.API.Designers.Property
{
    public class ProgramIDPropertyEditor : UITypeEditor
    {
        private IWindowsFormsEditorService editorService;

        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (provider != null)
            {
                editorService =
                    provider.GetService(
                    typeof(IWindowsFormsEditorService))
                    as IWindowsFormsEditorService;
            }

            ProgramNode pNode = (ProgramNode)context.Instance;

            if (editorService != null)
            {
                int projID = -1;

                

                using (ProgramSelectXtraForm psForm = new ProgramSelectXtraForm(pNode))
                {
                    if (editorService.ShowDialog(psForm) == DialogResult.OK)
                    {
                        value = psForm.selectedItem.projectObjectID;
                    }
                }

            }

            return value;
        }
    }
}
