/**
 * Widget constructor, this method is not used, instead of subclasses' constructors are used.
 * @extends HD.util.Observable
 * @constructor
 * 
 * @param config
 * 
 */
HD.Widget = function(config) {
	this.config = config;
};

HD.Widget.prototype = {
	/**
	 * Get a reference to the parent HTML element.
	 *
	 * @return The parent HTML element.
	 */
    getParent : function() {
    	return HD.util.Dom.get(this.config.parent);
    },
    
    /**
     * Render provided data and setup listeners.  This method calls subclass's getHtml() and setListeners() methods.
     * 
     * @param {Object} data The data to render
     */
    render : function(data) {
    	this.getParent().innerHTML = this.getHtml(data);
    	this.setListeners(data);
    },
    
    /**
     * Set up listeners for the rendered data.  This method is a placeholder to be implemented by subclasses.
     * 
     * @param {Object} data The data to set listeners for
     */
    setListeners : function(data) {
    	
    },
    
    /**
     * Destroy the content of the parent element.
     */
    destroy : function () {
    	this.getParent().innerHTML = "";
    },
    
    /**
     * Add/remove 'hdLoading' CSS class to/from the parent element.
     * 
     * @param {boolean} isShow Whether to show or hide loading indicator 
     */
    loading : function(isShow) {
		if(isShow) {
			HD.util.Dom.addClass(this.getParent(), HD.CSS_CLASSES.LOADING);
		} else {
			HD.util.Dom.removeClass(this.getParent(), HD.CSS_CLASSES.LOADING);
		}
    },
    
    /**
     * Listen and react to incoming events.  This method is a placeholder to be implemented by subclasses.
     * 
     * @param {String} eventName The name of the event
     * @param {Object} eventData The data associated with the event
     */
    update : function(eventName, eventData) {
    	
    },
    
    /**
    * Generate HTML based from the provided data.  This method is a placeholder to be implemented by subclasses.
    * 
    * @param {Object} data The data to generate HTML from
    */
    getHtml : function(data) {
    	return "";
    },
    
    /**
     * Get analystics string.  This method is a placeholder to be implemented by subclasses.
     */
    analyticsString : function() {
    	return "";
    }
};

HD.util.Common.extend(HD.Widget, [HD.util.Observable]);
