package com.guru.component.panel
{
	import com.guru.call.FunctionCall;
	import com.guru.call.ICall;
	import com.guru.display.progressBar.GuruProgressBar;
	import com.guru.component.panel.PanelBase;
	import com.guru.utils.ArrayUtil;
	import flash.display.MovieClip;
	/**
	 * ...
	 * @author Eddy Lee
	 */
	public class Panel
	{	
		public static var TNC:String = "tnc";
		public static var STATUS_BAR:String = "statusBar";
		public static var PROGRESS_BAR:String = "progressBar";
		public static var RANK:String = "rank";
		public static var FOOTER_RANK:String = "footerRank";
		public static var FRIEND:String = "friend";
		
		private static var sInstance:Panel;
		
		public static function getProgressBar():GuruProgressBar
		{
			return GuruProgressBar(getInstance().doGetPanel(PROGRESS_BAR));
		}
		
		public static function getPanel(pName_str:String):PanelBase
		{
			return getInstance().doGetPanel(pName_str);
		}
		
		public static function addPanel(pPanel:PanelBase):void
		{
			getInstance().doAddPanel(pPanel);
		}
		
		public static function hideStatusBar(pDoneCall:ICall = null):void
		{
			if (getPanel(STATUS_BAR))
			{
				getPanel(STATUS_BAR).hidePanel(pDoneCall);
			}
			else
			{
				if(pDoneCall)
					pDoneCall.execute();
			}
		}
		
		public static function showStatusBar(pType_str:String, pMsg_str:String = null, pShowDoneCall:ICall = null, pHideDoneCall:ICall = null):void
		{
			if (getPanel(STATUS_BAR))
			{
				getPanel(STATUS_BAR).hidePanel(new FunctionCall(Panel, Panel.showPanel, STATUS_BAR, pShowDoneCall, pHideDoneCall, { msg:pMsg_str, type:pType_str } ));
			}
			else
			{
				if(pShowDoneCall)
					pShowDoneCall.execute();
				
				if(pHideDoneCall)
					pHideDoneCall.execute();
			}
		}
		
		public static function hidePanel(pName_str:String, pDoneCall:ICall = null):void
		{
			getPanel(pName_str).hidePanel(pDoneCall);
		}
		
		public static function showPanel(pName_str:String, pShowDoneCall:ICall = null, pHideDoneCall:ICall = null, pData_obj:Object = null):void
		{
			if (pHideDoneCall)
				getPanel(pName_str).setHideDoneCall(pHideDoneCall);
				
			getPanel(pName_str).showPanel(pShowDoneCall, pData_obj);
		}
		
		private static function getInstance():Panel
		{
			if (sInstance == null)
				sInstance = new Panel();
				
			return sInstance;
		}
		
		private var mPanel_array:Array;
		
		public function Panel()
		{
			mPanel_array = new Array();
		}
		
		private function doGetPanel(pName_str:String):PanelBase
		{
			if (ArrayUtil.containsId(mPanel_array, pName_str))
			{
				return mPanel_array[pName_str];
			}
			else
			{
				trace("WARNING! Panel \"" + pName_str + "\" does not exist!");
			}
			
			return null;
		}
		
		private function doAddPanel(pPanel:PanelBase):void
		{
			if (!ArrayUtil.containsId(mPanel_array, pPanel.getName()))
			{
				mPanel_array[pPanel.getName()] = pPanel;
			}
			else
			{
				trace("WARNING! Panel \"" + pPanel.getName() + "\" already exist!");
			}
		}
	}

}