import { defineStore } from "pinia";

export const useGlobalStateStore = defineStore('globalState', {
    persist: true,
    state: () => ({
        lists: {}
    }),
    actions: {
        init: function (payload) {
            return new Promise((resolve, reject) => {
                if (typeof payload === 'object') {
                    if (typeof payload === 'object') {
                        for (const key in payload) {
                            if (payload.hasOwnProperty(key)) {
                                if (!this.lists[key]) {
                                    this.lists[key] = payload[key];
                                }
                            }
                        }
                    }
                    resolve(payload);
                } else {
                    reject("object not found");
                }
            });
        },
        set: function (payload) {
            return new Promise((resolve, reject) => {
                if (typeof payload === 'object') {
                    if (typeof payload === 'object') {
                        for (const key in payload) {
                            if (payload.hasOwnProperty(key)) {
                                this.lists[key] = payload[key];
                            }
                        }
                    }
                    resolve(payload);
                } else {
                    reject("object not found");
                }
            });
        }
    }
});
