using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using VSDev9.Controls;
using System.Collections.Generic;

namespace VSDev9
{
    public static class ControlsFactory
    {
        static Dictionary<string, Type> _controls = new Dictionary<string, Type>();

        static void AddControl<T>() 
        {
            _controls.Add(typeof(T).Name, typeof(T));
        }

        static ControlsFactory() 
        {
            // initialize controls factory
            AddControl<ClassView>();
            AddControl<CommandWindow>();
            AddControl<ErrorList>();
            AddControl<FileEditor>();
            AddControl<FindSymbolResults>();
            AddControl<Output>();
            AddControl<PendingChanges>();
            AddControl<Properties>();
            AddControl<ServerExplorer>();
            AddControl<SolutionExplorer>();
            AddControl<StartPage>();
            AddControl<TeamExplorer>();
            AddControl<Toolbox>();
        }

        public static Control Create(string name) 
        {
            if (!_controls.ContainsKey(name))
                throw new Exception(string.Format("Cannot create control {0}", name));

            var type = _controls[name];
            return (Control)type.GetConstructor(new Type[] { }).Invoke(new object[] { });
        }

        public static string GetControlKey(Control control) 
        {
            var typeName = control.GetType().Name;

            if (!_controls.ContainsKey(typeName))
                throw new Exception(string.Format("Cannot create control {0}", typeName));

            return typeName;
        }
    }
}
