var jsonfile = require("jsonfile");
var path = require("path");
var json_path = path.join(__dirname, "../public/data/json/profile/skroob.json");
var data = require(json_path);

exports.view = function(req, res) {
    query = req.query;
    console.log("FOO"); console.log(query);
    console.log("BAR"); console.log(data.songs[0].title);
    for (i in data.songs) {
        if (data.songs[i].title == query.title) {
            if (data.songs[i].highest < query.score) {
                data.songs[i].highest = query.score;
            }
            break;
        }
    }
    jsonfile.writeFile(json_path, data)
    data["redesign"] = false;
    res.render('profile', data);
}

exports.view_redesign = function(req, res) {
    query = req.query;
    for (i in data.songs) {
        if (data.songs[i].title == query.title) {
            if (data.songs[i].highest < query.score) {
                data.songs[i].highest = query.score;
            }
        }
    }
    jsonfile.writeFile(json_path, data)
    data["redesign"] = true;
    res.render('profile', data);
}
