var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promise, generator) {
    return new Promise(function (resolve, reject) {
        generator = generator.call(thisArg, _arguments);
        function cast(value) { return value instanceof Promise && value.constructor === Promise ? value : new Promise(function (resolve) { resolve(value); }); }
        function onfulfill(value) { try { step("next", value); } catch (e) { reject(e); } }
        function onreject(value) { try { step("throw", value); } catch (e) { reject(e); } }
        function step(verb, value) {
            var result = generator[verb](value);
            result.done ? resolve(result.value) : cast(result.value).then(onfulfill, onreject);
        }
        step("next", void 0);
    });
};
export class Storage {
    static saveLocalModel(model, modelName = 'model') {
        if (typeof window !== 'undefined' && window.localStorage) {
            // window.localStorage.setItem(modelName , btoa(JSON.stringify(model)));
            window.localStorage.setItem(modelName, JSON.stringify(model));
            window.localStorage.setItem(modelName + '-changed', String(Math.round(+new Date() / 1000)));
        }
        else {
            console.error('localStorage not available: not running in a browser');
        }
    }
    ;
    static restoreLocalModel(modelName = 'model') {
        if (typeof window !== 'undefined' && window.localStorage) {
            if (localStorage.getItem(modelName)) {
                // return JSON.parse(atob(localStorage.getItem(modelName)));
                return JSON.parse(localStorage.getItem(modelName));
            }
        }
        else {
            console.error('localStorage not available: not running in a browser');
        }
    }
    ;
    static flushLocalModel(modelName = 'model') {
        if (typeof window !== 'undefined' && window.localStorage) {
            if (localStorage.getItem(modelName)) {
                localStorage.removeItem(modelName);
            }
            if (localStorage.getItem(modelName + '-changed')) {
                localStorage.removeItem(modelName + '-changed');
            }
        }
        else {
            console.error('localStorage not available: not running in a browser');
        }
    }
    ;
}
//# sourceMappingURL=storage.js.map