package com.guru.panel
{
	import com.guru.call.FunctionCall;
	import com.guru.call.ICall;
	import com.guru.display.progressBar.GuruProgressBar;
	import com.guru.panel.PanelBase;
	import com.guru.utils.ArrayUtil;
	import flash.display.MovieClip;
	/**
	 * ...
	 * @author Eddy Lee
	 */
	public class Panel
	{	
		private static var sInstance:Panel;
		
		public static function getProgressBar():GuruProgressBar
		{
			return getInstance().mPanel_array["progressBar"];
		}
		
		public static function addPanel(pPanel:PanelBase):void
		{
			getInstance().doAddPanel(pPanel);
		}
		
		public static function hideStatusBar(pDoneCall:ICall = null):void
		{
			Panel.hidePanel("statusBar", pDoneCall);
		}
		
		public static function showStatusBar(pType_str:String, pMsg_str:String = null, pCloseDoneCall:ICall = null):void
		{
			Panel.hidePanel("statusBar", new FunctionCall(Panel, Panel.showPanel, "statusBar", pCloseDoneCall, { msg:pMsg_str, type:pType_str}));
		}
		
		public static function hidePanel(pName_str:String, pDoneCall:ICall = null):void
		{
			getInstance().doHidePanel(pName_str, pDoneCall);
		}
		
		public static function showPanel(pName_str:String, pHideDoneCall:ICall = null, pData_obj:Object = null):void
		{
			getInstance().doShowPanel(pName_str, pHideDoneCall, 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 doAddPanel(pPanel:PanelBase):void
		{
			if (!ArrayUtil.containsId(mPanel_array, pPanel.getName()))
			{
				mPanel_array[pPanel.getName()] = pPanel;
			}
			else
			{
				trace("WARNING! Panel \"" + pPanel.getName() + "\" already exist!");
			}
		}
		
		private function doHidePanel(pName_str:String, pDoneCall:ICall = null):void
		{
			if (ArrayUtil.containsId(mPanel_array, pName_str))
			{
				PanelBase(mPanel_array[pName_str]).hidePanel(pDoneCall);
			}
			else
			{
				trace("WARNING! Panel \"" + pName_str + "\" does not exist!");
			}
		}
		
		private function doShowPanel(pName_str:String, pHideDoneCall:ICall = null, pData_obj:Object = null):void
		{
			if (ArrayUtil.containsId(mPanel_array, pName_str))
			{
				PanelBase(mPanel_array[pName_str]).showPanel(null, pData_obj);
				PanelBase(mPanel_array[pName_str]).setHideDoneCall(pHideDoneCall);
			}
			else
			{
				trace("WARNING! Panel \"" + pName_str + "\" does not exist!");
			}
		}
		
	}

}