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

using System;

namespace Css{
	
	/// <summary>
	/// Describes if an element is last-child
	/// <summary>

	sealed class IsLastChild:CssKeyword{
		
		public override string Name{
			get{
				return "last-child";
			}
		}
		
		public override SelectorMatcher GetSelectorMatcher(){
			return new LastChildMatcher();
		}
		
	}
	
	/// <summary>
	/// Handles the matching process for :last-child.
	/// </summary>
	
	sealed class LastChildMatcher:LocalMatcher{
		
		public override bool TryMatch(Dom.Node node){
			
			if(node==null || node.parentNode==null){
				return false;
			}
			
			return (node.childIndex==(node.parentNode.childCount-1));
		}
		
	}
	
}