import { ref, computed } from 'vue';
import { defineStore } from 'pinia';

export const useStateQueryStore = defineStore('stateQueryStore', () => {
    const queries = ref(new Set());

    function add(query) {
        queries.value.add(query);
        return query;
    }

    function isLoading() {
        return computed(() => queries.value.size);
    }

    function remove(query) {
        queries.value.delete(query);
    }

    function reset() {
        queries.value = new Set();
    }

    return {
        add,
        isLoading,
        remove,
        queries,
        reset,
    };
});
