/**
 * state.js - Gestionnaire d'état synchronisé
 */
export const AvisionState = {
    data: {
        score: 42,
        lvl1Done: false,
        lvl1Timestamp: localStorage.getItem('avision_lvl1_time') || null,
        userEmail: localStorage.getItem('avision_user_email') || null,
        lang: 'en'
    },

    loadServerData: function(serverProgress) {
        if (serverProgress && serverProgress[1] === 'completed') {
            this.data.lvl1Done = true;
            this.data.lvl1Timestamp = localStorage.getItem('avision_lvl1_time');
        } else {
            this.data.lvl1Done = localStorage.getItem('avision_lvl1_done') === 'true';
        }
    },

    updateLvl1: function(status) {
        this.data.lvl1Done = status;
        const now = new Date().getTime();
        this.data.lvl1Timestamp = now;
        localStorage.setItem('avision_lvl1_done', status);
        localStorage.setItem('avision_lvl1_time', now);
    },

    saveEmail: function(email) {
        this.data.userEmail = email;
        localStorage.setItem('avision_user_email', email);
    }
};
