/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */


function loadProfile() {
    callAPI("getprofile", {
        username: localStorage.getItem("username"),
        password: localStorage.getItem("password"),
        id: $(".page[data-name=profile]").data("playerid")
    }, function (data) {
        console.log(data);
        $(".playerinfoflex").addClass("color-theme-" + SETTINGS.teams[data.profile.teamid].color);
        $("#playericon .usericon").html(getAvatarIcon(data.profile.id, data.profile.teamid));
        $("#playerteaminfo").html("<i class='" + SETTINGS.teams[data.profile.teamid].icon + "'></i> " + SETTINGS.teams[data.profile.teamid].name);
        $("#playerlevelinfo").html("Level " + data.profile.level * 1);

        data.profile.badges.forEach(function (badge) {
            $("#badgebin").append('<div class="badge" data-name="' + badge.name + '" data-desc="' + badge.desc + '" style="color: ' + badge.color + '; background: ' + badge.background + '"><i class="' + badge.icon + '"></i></div>');
        });

        $("#badgebin").on("click", ".badge", function () {
            var name = $(this).data("name");
            var desc = $(this).data("desc");
            app.popover.create({
                targetEl: this,
                backdrop: false,
                content: '<div class="popover">'+
              '<div class="popover-inner">'+
                '<div class="block">'+
                  '<b>' + name + '</b>'+
                  '<p>' + desc + '</p>'+
                '</div>'+
              '</div>'+
            '</div>'
            }).open();
        });
    }, function (err) {
        app.dialog.alert(msg, "Error");
    });
}