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

using System;
using Css.Units;


namespace Css{
	
	/// <summary>
	/// Handles the marker pseudo selector.
	/// <summary>

	sealed class Marker:CssKeyword{
		
		public override string Name{
			get{
				return "marker";
			}
		}
		
		public override SelectorMatcher GetSelectorMatcher(){
			return new MarkerSelector();
		}
		
	}
	
	/// <summary>
	/// Describes the marker psuedo-selector.
	/// <summary>

	public class MarkerSelector:PseudoSelectorMatch{
		
		public const int Priority=VirtualElements.BEFORE_ZONE+10;
		
		public static void Update(ComputedStyle style){
			
			// Get the ordinal:
			string ordinal=PowerUI.HtmlOListElement.GetOrdinal(style,true);
			
			if(ordinal==""){
				
				// (None). Remove the marker:
				style.RemoveVirtual(MarkerSelector.Priority);
				
			}else{
				
				// Require marker:
				Dom.Element node=style.GetOrCreateVirtual(MarkerSelector.Priority,"span",true) as Dom.Element;
				
				node.style.display="inline-block";
				node.style.width="40px";
				node.style.left="-40px";
				node.style.textAlign="right";
				node.style.position="-spark-absolute";
				
				// Write its content now:
				node.innerHTML=ordinal;
				
			}
			
		}
		
		public override void Select(CssEvent e){
			
			// Get the v-child (this one does not create it if it doesn't exist):
			GetVirtual(e,Priority);
			
		}
		
	}
	
}