/**
 * @class HD.DetailWidget
 * @description The purpose of DetailWidget is to display the full contents of a media entry.
 * @constructor
 * @extends HD.Widget
 * @see HD.DetailWidget.hooks
 * @see HD.DetailWidget.templates
 * @property {object} config
 *                 The configuration for the widget.
 * @property {string}  config.dateFormat
 *                 The format that dates for media should be displayed in.
 * @property {object}  [config.hooks=HD.DetailWidget.hooks]
 *                 Customized subset of hooks (merged with the defaults).
 * @property {boolean} [config.embedSendFriend=false]
 *                 Whether to embed a HD.SendFriendWidget within each media.
 * @property {boolean} [config.embedShare=false]
 *                 Whether to embed a HD.ShareWidget within each media.
 * @property {object}  [config.sendFriendConfig=false]
 *                 The widget configuration for the embedded HD.SendFriendWidget.
 * @property {object}  [config.shareConfig=false]
 *                 The widget configuration for the embedded HD.ShareWidget.
 * @property {object}  [config.templates=HD.DetailWidget.templates]
 *                 Customized subset of templates (merged with the defaults).
 * @property {object}  [config.blogHooks]
 *                 Customized subset of hooks for HD.community.Blog media.
 * @property {object}  [config.blogTemplates]
 *                 Customized subset of templates for HD.community.Blog media.
 * @property {number}  [config.playerHeight=300]
 *                 Height (in pixels) for an hd_player object.
 * @property {number}  [config.playerWidth=400]
 *                 Width (in pixels) for an hd_player object.
 * @property {object}  [config.photoHooks]
 *                 Customized subset of hooks for HD.community.Photo media.
 * @property {object}  [config.photoTemplates]
 *                 Customized subset of templates for HD.community.Photo media.
 * @property {object}  [config.videoHooks]
 *                 Customized subset of hooks for HD.community.Video media.
 * @property {object}  [config.videoTemplates]
 *                 Customized subset of templates for HD.community.Video media.
 */
HD.DetailWidget = function(config) {
    this.config = config;
    
	/** Observers collection */
    this.observers = [];
	this.loadTemplates(arguments.callee);
};

/**
 * The collection of default templates.
 */
HD.DetailWidget.templates = {
	/**
	 * @constant
	 * @return {string} Main template for the widget
	 * @memberOf HD.DetailWidget
	 */
	getHtml : function() {
		return this.html;
	},
	
	/** 
	 * Main template for the widget
	 * @memberOf HD.DetailWidget
	 * @type jst_template
	 */
	html :  '\
		{if data}\
			<div class="${classes.DETAIL} ${classes.WIDGET}">\
				${data|facade}\
			</div>\
		{/if}'
};
	
HD.DetailWidget.prototype = {
	/**
	 * Sets event listeners for the widget.
	 * @param {object} [data]
	 *                 Event data from the render phase
	 */
    setListeners : function(data) {
    	if(data != null) {    		
			HD.util.Analytics.track(this.analyticsString(data));
    		data.facade.setListener(this.getParent(), this);
    	}
    },
    
	/**
	 * 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 == "getMedium_Start") {
    		this.loading(true);
    	} else if(eventName == "getMedium_Finish") {
			// activeItem_Change is fired too, no need to render twice.
    		this.loading(false);
    	} else if(eventName == "activeItem_Change") {
    		this.loading(false);
    		this.render(eventData);    		
    	}
    },
    
	/**
	 * Renders the HTML for the widget based on dynamic data.
	 * @param {object} [data]
	 *                 Event data from the render phase
	 * @returns HTML for the widget
	 * @type string
	 */
    getHtml : function(data) {
		return this.processTemplate(this.config.templates.getHtml(), {
			data : data
		});
    },
  
	/**
	 * Generates an analytics string.
	 * @param {object} [data]
	 *                 Data relevant to the analytics call.
	 * @returns Analytics string based on the data.
	 * @type string
	 */
    analyticsString : function(data) {
    	return "default_analyticsDetailString";
    }
    
};

HD.extend(HD.DetailWidget, [HD.Widget]);

HD.register('hd_detail_widget', 'HD.DetailWidget', {version: "1.0", build: "1"});
