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

using System;
using PowerUI;


namespace Css.Units{
	
	/// <summary>
	/// Represents an instance of a viewport relative value, e.g. vmax.
	/// </summary>
	
	public class ViewPortMaxUnit:ViewPortUnit{
		
		public override float DisplayNumber{
			get{
				return (RawValue * 100f);
			}
		}
		
		public override string ToString(){
			return DisplayNumber+"vmax";
		}
		
		public override void OnValueReady(CssLexer lexer){
			// Map to 0-1 range:
			RawValue /= 100f;
		}
		
		public override float GetDecimal(RenderableData context,CssProperty property){
			
			Viewport vp=context.Document.Viewport;
			
			float w=vp.Width;
			float h=vp.Height;
			
			if(w > h){
				return RawValue * w;
			}else{
				return RawValue * h;
			}
			
		}
		
		protected override Value Clone(){
			ViewPortMaxUnit result=new ViewPortMaxUnit();
			result.RawValue=RawValue;
			return result;
		}
		
		public override string[] PostText{
			get{
				return new string[]{"vmax"};
			}
		}
		
	}
	
}



