/**
 * 
 */
package org.richfaces.realworld.tagClound;

import java.util.HashMap;
import java.util.Map;

import javax.faces.event.ActionEvent;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;


/**
 * Tag cloud backing bean
 * @author Andrey Markavtsov
 *
 */

@Name("tagCloudBean")
@Scope(ScopeType.CONVERSATION)
public class TagCloudBean {
	
	/** Min possible rank for tag  */
	static final int MIN_RANK = 0;
	
	/** Max possible rank for tag  */
	static final int MAX_RANK = 100;
	
	/** Scope of existed css classes for each rank. Should be defined ordered ASC by rank */
	static final String [] TAG_CSS_CLASSSES = new String [] 
	          {"tag-cloud-rank1", "tag-cloud-rank2", 
			   "tag-cloud-rank3", "tag-cloud-rank4", 
			   "tag-cloud-rank5", "tag-cloud-rank6", 
			   "tag-cloud-rank7" } ;
	
	/** Count of possible ranks' css classes */
	static final int TAG_RANK_LEVELS_COUNT = TAG_CSS_CLASSSES.length;
	
	/** Defines the step to the neighbouring rank */
	int RANK_LEVEL_STEP = (MAX_RANK ) / TAG_RANK_LEVELS_COUNT;;
	
	//@In
	//ITagCloudProvider cloudProvider;
	
	
	/**
	 * @return map of tags
	 */
	@Out
	public Map<String, Integer> getTags() {
		/*if (cloudProvider == null) {
			throw new NullPointerException("Cloud tag provider is null");
		}*/
		//return cloudProvider.getTags();
		Map<String,Integer> tags = new HashMap<String,Integer>();
		tags.put("Tag1", 12);
		tags.put("Tag2", 65);
		tags.put("Tag3", 89);
		tags.put("Tag4", 39);
		tags.put("Tag5", 7);
		tags.put("Tag6", 59);
		tags.put("Tag7", 71);
		tags.put("Tag8", 85);
		tags.put("Tag9", 29);
		return tags;
		
	}
	
	
	/**
	 * Calculates css class name for tag with rank defined 
	 * @param rank - tags rank
	 * @return css class name
	 */
	public String getTagCssClass(Integer rank) {
		int i = rank / RANK_LEVEL_STEP;
		return TAG_CSS_CLASSSES[i];
	}
	
	
	
	/**
	 * Action listener for tag click
	 * @param event
	 */
	public void processTagClick(ActionEvent event) {
		// TODO: implement this
	}

}
