using System.Collections;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace EVE.EVEShaders
{
    public class EVEShaderManager
    {
        private static Dictionary<string, EVEShader> myEffects = new Dictionary<string, EVEShader>();
        private static Dictionary<string, EVEShader> myPostProc = new Dictionary<string, EVEShader>();

        private static List<string> myPostList = new List<string>();

        public static void AddEffect(string shaderLabel, EVEEffect newShader)
        {
            myEffects.Add(shaderLabel, newShader);
        }

        public static void AddPostProc(string shaderLabel, EVEPostProc newPostProc)
        {
            myPostProc.Add(shaderLabel, newPostProc);
        }

        internal static EVEShader GetShader(string shaderLabel)
        {
            if (shaderLabel != null && myEffects.ContainsKey(shaderLabel))
                return myEffects[shaderLabel] as EVEShader;
            if (shaderLabel != null && myPostProc.ContainsKey(shaderLabel))
                return myPostProc[shaderLabel] as EVEShader;

            return myEffects["Microsoft.Xna.Framework.Graphics.BasicEffect"];
        }


        internal static EVEShader GetPost(string shaderLabel)
        {

            if (shaderLabel != null && myPostProc.ContainsKey(shaderLabel))
                return myPostProc[shaderLabel] as EVEShader;

            return myEffects["Microsoft.Xna.Framework.Graphics.BasicEffect"];
        }


        internal static void Initialize()
        {
            EVEEffect BasicEffect = new EVEEffect();

            myEffects.Add("Microsoft.Xna.Framework.Graphics.BasicEffect", BasicEffect);

            //EVEPostProc BasicPost = new EVEEffect();

            //myPostProc.Add("BasicPost", BasicPost);
        }

        internal static void LoadContent(GraphicsDevice myDevice, ContentManager myLoader)
        {
            foreach (EVEShader shader in myEffects.Values)
            {
                shader.LoadContent(myDevice, myLoader);
            }

            foreach (EVEShader shader in myPostProc.Values)
            {
                shader.LoadContent(myDevice, myLoader);
            }
        }

        //*******************************************************************
        //*********************POST PROCESSING*******************************
        //*******************************************************************
        internal static void PostProcess(GraphicsDevice myDevice)
        {
            foreach (string postLabel in myPostList)
            {
                EVEPostProc aPost = GetShader(postLabel) as EVEPostProc;
                aPost.Draw(myDevice);
            }
        }

        public static void AddToPost(string postLabel)
        {
            myPostList.Add(postLabel);
        }

        public static void ClearPost()
        {
            myPostList.Clear();
        }
    }
}