Template.comment.helpers({
    submittedText: function() {
       	var date = new Date(this.submitted);
    	console.log("vote =====>", this);
    	var d=date.getDate();
    	var m=date.getMonth()+1;
    	var y=date.getFullYear();

        return m + " - " + d + " - " + y;
    },
    postID : function(postID){
        this.postID = postID;
        return postID;
    },
    up: function(){
    var userId = Meteor.userId();
        if (userId && _.include(this.upvoters, userId)) {

            return true;
        } else{

        	return false;
        }
    },
    down: function(){
    	var userId = Meteor.userId();
        if (userId && _.include(this.downvoters, userId)) {

            return true;
        }else{

        	return false;
        }

    },
	// we will have to edit this function
    upvotedClass: function() {
        var userId = Meteor.userId();
        if (userId && ( !_.include(this.upvoters, userId) || _.include(this.downvoters, userId) ) ) 
 else {
            return 'disabled';
        }
    },
	downvotedClass: function() {
        var userId = Meteor.userId();
        if (userId && ( !_.include(this.downvoters, userId) || _.include(this.upvoters, userId) ) ) {
            return 'downvotable';
        } else {
            return 'disabled';
        }
    },
});


Template.comment.events({
	'click .upvotable': function(e) {
		e.preventDefault();
		console.log("e =====>", e);
		var postID = this.postID;
		Meteor.call('upvoteComment', this._id, postID);
	},
	'click .downvotable': function(e) {
		e.preventDefault();
		console.log("e =====>", e);
		var postID = this.postID;
		Meteor.call('downvoteComment', this._id, postID);
	},
	'click .translatable': function(e,t) {
		var curTarget = $(e.currentTarget),
		srcTxt = this.body,
		srcLang = 'en',
        tarLang = 'de';

		Meteor.call('getTranslation', srcTxt, srcLang, tarLang, function(err, res){
            if (res.error) {console.log("err", res.message); curTarget.closest('div.row').find('.translated-text').text('(' + "sorry, something went wrong" + ')');}
            else curTarget.closest('div.row').find('.translated-text').text('(' + res.message + ')');
        });
	}
});


{
            return 'upvotable';
        }