/**
 * @class HD.MemberWidget
 * @description The purpose of MemberWidget is to display an overlay with detailed information 
 *              about a given member (usually authors for media).
 * @constructor
 * @extends HD.Widget
 * @see HD.MemberWidget.hooks
 * @see HD.MemberWidget.templates
 * @property {object} config
 *                 The configuration for the widget
 * @property {object} [config.hooks=HD.MemberWidget.hooks]
 *                 Customized subset of hooks (merged with the defaults).
 * @property {object} [config.templates=HD.MemberWidget.templates]
 *                 Customized subset of templates (merged with the defaults).
 * @property {string}  config.title
 *                 The title for the overlay.
 */

HD.MemberWidget = function(config) {
    this.config = config;
    
	/** Observer collection */
    this.observers = [];
	this.loadTemplates(arguments.callee);
};

/**
 * The collection of default templates.
 */
HD.MemberWidget.templates = {
	/**
	 * Text to display when no public profile could be found
	 * @memberOf HD.MemberWidget
	 */
	noProfileText      : 'This user does not have a public profile.',
	
	/**
	 * @constant
	 * @return {string} Text to display when no public profile could be found
	 * @memberOf HD.MemberWidget
	 */
	getNoProfileText : function() {
		return this.noProfileText;
	},
	
	/**
	 * @constant
	 * @return {string} Main template for the widget
	 * @memberOf HD.MemberWidget
	 */
	getHtml : function() {
		return this.html;
	},
		
	/** 
	 * Main template for the widget
	 * @memberOf HD.MemberWidget
	 * @type jst_template
	 */
	html :  '\
		<div class="${classes.MEMBER} ${classes.WIDGET}">\
		{if profile}\
			<div class="dblRuleBtm"><span class="head">${config.title}</span></div>\
			<div class="${classes.THUMB}" {if profile.pathToProfilePhoto}style="background: transparent url(${profile.pathToProfilePhoto}) no-repeat 50% 50%;"{/if}></div>\
			<div class="${classes.DESCRIPTION}">\
				<div class="${classes.TITLE}">${profile.firstName} ${profile.lastName}</div>\
				<div class="${classes.VALUE}">${profile.aboutMe}</div>\
			</div>\
		{else}\
			${templates.getNoProfileText()}\
		{/if}\
		</div>'
};

HD.MemberWidget.prototype = {
	/**
	 * Monitors events by HD.CommunityDAO.
	 * @param {string} eventName
	 *                 The name of the event
	 * @param {object} [eventData]
	 *                 Data for the event
	 */
    update : function(eventName, eventData) {
    	if(eventName == "getMember_Start") {
    		this.loading(true);
    	} else if(eventName == "getMember_Finish") {
    		this.loading(false);
    		this.render(eventData);
    	}
    },
    
	/**
	 * Renders the HTML for the widget based on dynamic data.
	 * @param {object} [profile]
	 *                 Event data for a profile to be displayed
	 * @returns HTML for the widget
	 * @type string
	 */
    getHtml : function(profile) {
		return this.processTemplate(this.config.templates.getHtml(), {
			profile : profile
		});
    }
};

HD.extend(HD.MemberWidget, [HD.Widget]);

HD.register('hd_member_widget', 'HD.MemberWidget', {version: "1.0", build: "1"});
