//--------------------------------------
//               PowerUI
//
//        For documentation or 
//    if you have any issues, visit
//        powerUI.kulestar.com
//
//    Copyright © 2013 Kulestar Ltd
//          www.kulestar.com
//--------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;


namespace PowerUI{
	
	/// <summary>
	/// The scripting engines which deal with the script tag.
	/// </summary>
	
	public static class ScriptEngines{
		
		/// <summary>The available script engines.</summary>
		public static Dictionary<string,ScriptEngine> All;
		
		
		/// <summary>Adds a scripting engine.</summary>
		public static void Add(ScriptEngine engine){
			
			if(All==null){
				All=new Dictionary<string,ScriptEngine>();
			}
			
			string[] types=engine.GetTypes();
			
			if(types==null){
				return;
			}
			
			for(int i=0;i<types.Length;i++){
				All[types[i].Trim().ToLower()]=engine;
			}
			
		}
		
		/// <summary>Gets the scripting engine for the given type (e.g. "text/javascript").</summary>
		public static ScriptEngine Get(string tag){
			
			if(All==null){
				return null;
			}
			
			ScriptEngine engine;
			All.TryGetValue(tag.Trim().ToLower(),out engine);
			
			return engine;
			
		}
		
	}
	
}