/*
User preferences via local storage

@copyright (c) Copyright 2013-2016 Dorian Pula
@license AGPL v3
@author Dorian Pula [dorian.pula@amber-penguin-software.ca]
*/

export class UserInfo {
    static getInitialInfo() {
        return {
            theme: "evening",
            editor_theme: "monokai",
            full_name: "Stranger",
            auth_token: ""
        }
    }

    static getUserInfo(info) {
        console.log(`Getting user info '${info}'`);
        let storageKey = `user_${info}`;
        let infoItem = localStorage.getItem(storageKey);
        if (infoItem === undefined) {
            infoItem = UserInfo.getInitialInfo()[info];
        }

        return infoItem;
    }

    static setUserInfo(info, value) {
        console.log(`Setting user info '${info}' to '${value}'`);
        localStorage.setItem(`user_${info}`, value);
    }

    static removeUserInfo(info) {
        console.log(`Clearing user info '${info}'`);
        localStorage.removeItem(`user_${info}`);
    }
}
