$(function () {
	$('#myStat').circliful();
});

(function getProgressInformation () {
	var subHeadingData = $.parseJSON($.cookie("iCuroUser"));
	var workerId = subHeadingData.USER;
	icuro.api.progress.byWorkerID(workerId, getProgressInformationHandler);
})()

function getProgressInformationHandler (responseText) {
	var responseObj = JSON.parse(responseText);
	var rendered;
	var loopDate;
	// Mustache.parse(template);
	var htmlNotToday = '<li>{{description}} - Updated by {{updated_by}} on {{updated}}</li>';
	var htmlIsToday = '<li class="orange">{{description}} - Updated by {{updated_by}} on {{updated}}</li>';
	var today = new Date();

	console.log(responseObj);

	$('#worker-progress-list').html('');

	if (responseObj.results) {
		
		for (var i = 0; i < responseObj.results.length; i++) {
			// check if the date passed through is same as today, if so, add class
			loopDate = new Date(responseObj.results[i].updated);
			if (today.isSameDateAs(loopDate)) {
				console.log("Date passed through is today.");
				rendered = Mustache.render(htmlIsToday, responseObj.results[i]);
				$('#worker-progress-list').append(rendered);
			} else {
				rendered = Mustache.render(htmlNotToday, responseObj.results[i]);
				$('#worker-progress-list').append(rendered);
			}
		}

	} else {
		$('#error-message').html("You don't have any progress to report. Check back later.")
		$('#error-message').fadeIn();
	}
	
}