const fakeStorage = {
    _data: {},
    /**
     * Get fake storage value from key identifier
     *
     * @param key
     * @returns
     */
    getItem: (key) => {
        if (Object.prototype.hasOwnProperty.call(fakeStorage._data, key)) {
            return fakeStorage._data[key];
        }
        return null;
    },
    /**
     * Set value to fake storage from key identifier
     *
     * @param key
     * @param obj
     */
    setItem: (key, obj) => {
        fakeStorage._data[key] = obj;
    },
    /**
     * Remove fake storage from key identifier
     *
     * @param key
     */
    removeItem: (key) => {
        if (Object.prototype.hasOwnProperty.call(fakeStorage._data, key)) {
            delete fakeStorage._data[key];
        }
    },
};
const getStorage = () => {
    try {
        return window.localStorage;
    }
    catch (err) {
        return fakeStorage;
    }
};
const OJSON = window.JSON;
const storage = getStorage();
const StorageService = {
    /**
     * Get storage value from key identifier
     *
     * @param key
     * @returns
     */
    get(key) {
        let value = storage.getItem(key);
        if (/^\{.*\}$/.test(value)) {
            value = OJSON.parse(value);
        }
        return value;
    },
    /**
     * Set value to storage from key identifier
     *
     * @param key
     * @param value
     * @returns
     */
    set(key, value) {
        if (typeof value === typeof {}) {
            value = OJSON.stringify(value);
        }
        return storage.setItem(key, value);
    },
    /**
     * Remove storage from key identifier
     *
     * @param key
     * @returns
     */
    remove(key) {
        return storage.removeItem(key);
    },
};
const create = () => Object.assign((key, value) => StorageService.set(key, value), StorageService);
export const Store = create();
