/**
 * Confirmation widget for rendering the confirmation page upon successful enrollment 
 * in a Rider's Edge course.
 * @extends HD.Widget
 * 
 * @param {Object} config configuration object containing configurable properties 
 * @param {HD.REO.Model} model the model object, signals model events
 * @param {HD.REO.View} view the view object, facilitates the communication of events between widgets 
 */
HD.REO.View.Confirmation = function(config, model, view) {
	this.observers = [];
	this.config = config || {};
    
	if(model != null) {
		this.model = model;
		this.model.addObserver(this);
	}
	
	if(view != null) {
		this.view = view; 
	    this.view.addObserver(this);
	}
};

/**
 * Template object containing overrideable methods and properties.
 * @static
 */
HD.REO.View.Confirmation.template = {
	copyText1 : '<p>You\'re one step closer to the open road.  You\'ll receive a confirmation e-mail shortly.</p>' +
				'<br/>'+
				'<p>To complete your enrollment in the class, a representative from _DEALER_NAME will be contacting you within '+
				'1 to 2 business days.  The dealership will confirm your student identification number with you.  Once confirmed, '+
				'they will discuss payment options, cancellation policies, dealership agreements and other important information '+
				'you will need to prepare for the class.</p>'+
				'<br/>'+
				'<p class="hdBold">Your confirmation enrollment in the class is not complete until you have paid for the class and '+
				'agreed to all applicable dealership policies associated with enrollment.  This may require signing forms at the '+
				'dealership or providing credit card information over the phone.</p>',
	copyText2 : 'Harley-Davidson dealers are independent businesses and are not agents of Harley-Davidson Motor Company.  Therefore, ' +
				'each authorized Rider\'s Edge dealer has cancellation policies specific to their dealership.  Harley-Davidson Motor ' +
				'Company does not have responsibility for cancellation policies made by the dealership.  Contact this dealer to find ' +
				'out more about their cancellation policy.',
	promoText : 'Or, to pay now, please call _DEALER_NAME at (_NPA) _NXX-_STATION and ask to speak with someone about your Rider\'s Edge ' +
				'course enrollment._PROMO1_PROMO2',
	promoLink1 : '<a href="javascript:void(0)" onclick="window.location=HD.util.Common.switchProtocol(\'http\', \'/wcm/Content/Pages/Accessories_and_Apparel/Accessories_and_Apparel.jsp?locale=en_US\')"><div class="promoImage1"></div></a>',
	promoLink2 : '<a href="javascript:void(0)" onclick="window.location=HD.util.Common.switchProtocol(\'http\', \'/wcm/Content/Pages/Motorcycles/motorcycles.jsp?locale=en_US\')"><div class="promoImage2"></div></a>',
	
	getCopyText1 : function(dealerName) {
		return HD.REO.View.Confirmation.template.copyText1.replace(/_DEALER_NAME/, dealerName);
	},
	
	getCopyText2 : function(dealerName) {
		return HD.REO.View.Confirmation.template.copyText2;
	},
	
	getPromotText : function(dealerName, phone) {
		var html = this.promoText;
		html = html.replace(/_DEALER_NAME/, dealerName);
		html = html.replace(/_NPA/, phone.npa);
		html = html.replace(/_NXX/, phone.nxx);
		html = html.replace(/_STATION/, phone.station);
		html = html.replace(/_PROMO1/, this.promoLink1);
		html = html.replace(/_PROMO2/, this.promoLink2);
		return html;
	}
};

HD.REO.View.Confirmation.prototype = {
	/**
	 * @see HD.Widget#update 
	 */
	update : function(eventName, eventData) {
		if(eventName == "model_GetSelectedCourse_Start") {
			this.loading(true);
		} else if(eventName == "model_GetSelectedCourse_Finish") {
			var typeOfRegistration = eventData.openSeats > 0 ? "Reservation" : "Waiting+List";
			var courseType = HD.REO.template.courseTypesLabels[eventData.type].replace(/ /, "+");
			HD.util.Analytics.track(HD.REO.analytics.getSignupConfirmation(courseType, typeOfRegistration));
			this.loading(false);
			this.render(eventData);
		}
	},
	
	/**
	 * @see HD.Widget#setListeners 
	 */
	setListeners : function(data) {},
	
	/**
	 * @see HD.Widget#getHtml 
	 */
	getHtml : function(data) {
    	var classes = HD.CSS_CLASSES;
    	var reoClasses = HD.REO.View.CSS_CLASSES;
    	
    	var template = HD.REO.View.Confirmation.template;
    	
    	var date = HD.util.Date;
    	
    	var dateFormat = "mmm d',' yyyy";
    	var dayFormat = "ddd";
    	
    	var dealer = data.dealer;
    	var address = dealer.address;
    	var phone = dealer.phone;
    	
    	return ['<div class="', classes.WIDGET, ' ', reoClasses.CONFIRMATION ,'">' , 
	    	        '<div class="copy hdInfo">',
	    	        	template.getCopyText1(dealer.name),
		    	    '</div>',
		    	    '<div class="promos hdInfo">',
		    	    	template.getPromotText(dealer.name, phone),
		    	    '</div><br/>',
		    	    '<div class="classInfo1 hdInfo">',
		    	    	'<div class="hdInfoItem">',
		    	    		'<div class="hdTitle"><h4>Reservation ID Number</h4></div>',
		    	    		data.studentId,
		    	    	'</div>',
		    	    	'<div class="hdInfoItem">',
		    	    		'<div class="hdTitle"><h4>Course</h4></div>',
		    	    		'Rider\'s Edge&reg; ', HD.REO.template.courseTypesLabels[data.type] ,' Course (ID#', data.id , ')',
		    	    	'</div>',
		    	    	'<div class="hdInfoItem">',
		    	    		'<div class="hdTitle"><h4>Schedule</h4></div>',
		    	    		HD.REO.View.Schedule.template.getSchedule(data),
		    	    	'</div>',
		    	    '</div>',
		    	    '<div class="classInfo2 hdInfo">',
		    	    	'<div class="hdInfoItem">',
		    	    		'<div class="hdTitle"><h4>Pricing</h4></div>',
		    	    		'The class fee is $', data.fee ,
		    	    	'</div>',
		    	    	'<div class="hdInfoItem">',
		    	    		'<div class="hdTitle"><h4>Location</h4></div>',
		    	    		HD.REO.View.List.template.getDealerContact(dealer), 
		    	    	'</div>',
		    	    '</div>',
		    	    '<div class="cancelation hdInfo">',
		    	    	'<div class="hdInfoItem">',
		    	    		'<div class="hdTitle"><h4>Cancellation Policy</h4></div>',
		    	    		template.getCopyText2(),
		    	    	'</div>',
		    	    '</div>',
				'</div>'].join('');
	}
};

HD.util.Common.extend(HD.REO.View.Confirmation, [HD.Widget]);