﻿package com.adobe.captivate.widgets
{
	/**
		* This class decscribes the handle Adobe Captivate passes  to the widget during runtime using the cpSetValue function.
	*/
	public class CPMovieHandle
	{
		/**
     		* @private
     	*/
		private var _widgetParams:Function;
		/**
     		* @private
     	*/
		private var _replaceVariables:Function;
		/**
     		* @private
     	*/
		private var _getContainerProps:Function;
		/**
     		* @private
     	*/
		private var _getSlideProps:Function;
		/**
     		* @private
     	*/
		private var _getMovieProps:Function;
		/**
     		* @private
     	*/
		private var _isWidgetVisible:Function;
		/**
     		* @private
     	*/
		private var _isWidgetEnabled:Function;
		/**
     		* @private
     	*/
		private var _getCPRandomPoolSlideProperties:Function;
		
		/**
     		* @private
     	*/
		private var _getCPQuestionPoolProperties:Function;
		
		/**
     		* @private
     	*/
		private var _getCPSlideData:Function;
		
		/**
     		* @private
     	*/
		private var _getCPQuizData:Function;
		
		/**
     		* @private
     	*/
		
		private var _getCPQuestionData:Function;
		
		/**
     		* @private
     	*/
		
		public function CPMovieHandle(aWidgetParams:Function=null,aReplaceVariables:Function=null,aGetContainerProps:Function=null,
			aGetSlideProps:Function=null,aGetMovieProps:Function=null,aIsWidgetVisible:Function=null,aIsWidgetEnabled:Function=null,
			aGetCPRandomPoolSlideProperties:Function = null,aGetCPQuestionPoolProperties:Function=null,aGetCPSlideData:Function = null,aGetCPQuizData:Function = null,
			aGetCPQuestionData:Function = null)
		{
			_widgetParams = aWidgetParams;
			_replaceVariables = aReplaceVariables;
			_getContainerProps = aGetContainerProps;
			_getSlideProps = aGetSlideProps;
			_getMovieProps = aGetMovieProps;
			_isWidgetVisible = aIsWidgetVisible;
			_isWidgetEnabled = aIsWidgetEnabled;
			_getCPQuestionPoolProperties = aGetCPQuestionPoolProperties;
			_getCPRandomPoolSlideProperties = aGetCPRandomPoolSlideProperties;
			_getCPSlideData = aGetCPSlideData;
			_getCPQuizData = aGetCPQuizData;
			_getCPQuestionData = aGetCPQuestionData;
		}
		
		/**
     		* The widget parameter provided by the widget during edit time.
			
			* @return A String containing the widget parameters
     	*/
		public function widgetParams() :String
		{
			var lWidgetParams:String = "";
			if(_widgetParams!= null)
			{
				lWidgetParams = _widgetParams();
			}
			return lWidgetParams;
		}
		
		/**
     		* This function replaces any string with variable names enclosed in $$  with the value of the variable at runtime.
			* <listing version="3.0">
			* movieHandle.replaceVariables( "$$JohnDoe$$ scored $$cpQuizInfoPointsscored$$ out of $$cpQuizInfoTotalQuizPoints$$") 
			* </listing>
			* returns 
			* "JohnDoe scored 10 out of 100" assuming that JohnDoe scored 10 points out of the total 100 that was set in Adobe Captivate
			*
			* @param  A String containg zero or more variables enclosed in $$ to be replaced with their values at runtime
			* @return A String containg the variables replaced with their values
     	*/
		public function replaceVariables( varString:String ) :String
		{
			var replacedString = "";
			if(_replaceVariables != null)
			{
				replacedString  = _replaceVariables(varString);
			}
			return replacedString;
		}
		
		/**
     		* This function returns the properties of the container containg the widget.
			
			* @return A CPContainerProperties Object 
			
			* @see CPContainerProperties
		*/
		public function getContainerProps() :CPContainerProperties
		{
			var lProps:CPContainerProperties = null;
			if(_getContainerProps != null)
			{
				lProps = _getContainerProps();
			}
			return lProps;
		}
		
		/**
     		* This function returns the properties of the slide containing the widget.
			
			* @return A CPSlideProperties Object 
			
			* @see CPSlideProperties
		*/
		public function getSlideProps() :CPSlideProperties
		{
			var lSlideProps:CPSlideProperties = null;
			if(_getSlideProps != null)
			{
				lSlideProps = _getSlideProps();
			}
			return lSlideProps;
		}
		
		/**
     		* This function returns the properties of the Adobe Captivate movie that is closest to the hierarchy of the widget.
			
			* @return A CPMovieProperties Object 
			
			* @see CPMovieProperties
		*/
		public function getMovieProps() :CPMovieProperties
		{
			var lMovieProps:CPMovieProperties  = null;
			if(_getMovieProps != null)
			{
				lMovieProps = _getMovieProps();
			}
			return lMovieProps;
		}
		
		/**
     		* This function returns if the widget is currently visible on stage.
			
			* @return <code>true</code> is widget is visible <code>false</code> otherwise 			
		*/
		
		public function isWidgetVisible() :Boolean
		{
			var lVisibilty:Boolean = false;
			if( _isWidgetVisible != null )
			{ 
				lVisibilty = _isWidgetVisible();
			}
			return lVisibilty;
		}
		
		/**
     		* This function returns whether the widget is enabled.
			* A widget is considered as enabled when it is present on the slide or on the Timeline. 
			* All functions discussed work only if isWidgetEnabled() returns true
			* @return <code>true</code> is widget is enabled <code>false</code> otherwise 			
		*/
		
		public function isWidgetEnabled():Boolean
		{
			var lEnabled:Boolean = false;
			if( _isWidgetEnabled != null )
			{
				lEnabled = _isWidgetEnabled();
			}
			return lEnabled;
		}
		
		/**
     		* This function returns the properties of the pool slide which replaces the random slide placeholder.
			* @param - index of the random placeholder slide			
			* @return A CPRandomPoolSlideProperties object
			* @see CPRandomPoolSlideProperties			
		*/
		public function getCPRandomPoolSlideProperties(idx:int):CPRandomPoolSlideProperties
		{
			if(_getCPRandomPoolSlideProperties != null)
			{
				return _getCPRandomPoolSlideProperties(idx);
			}
			return null;
		}
		
		public function getCPQuestionPoolProperties(aPoolName:String):CPQuestionPoolProperties
		{
			if(_getCPQuestionPoolProperties!= null)
			{
				return _getCPQuestionPoolProperties(aPoolName);
			}
			return null;
		}
		
		public function getCPSlideData(idx:uint):CPSlideData
		{
			if(_getCPSlideData != null)
			{
				return _getCPSlideData(idx);
			}
			return null;
		}
		
		public function getCPQuizData():CPQuizData
		{
			if(_getCPQuizData != null)
			{
				return _getCPQuizData();
			}
			return null;
		}
		
		public function getQuestionData():CPQuestionData
		{
			if(_getCPQuestionData != null)
				return _getCPQuestionData();
			return null;	
		}
	}
}

