import {defineStore} from 'pinia'
import {config} from '@/config'
import performRequest from "@/backend.js";


export const useGroupStore = defineStore('group', {
    state: () => ({
        groups: [],
        loading: false,
    }),
    getters: {
        getById: (state) => {
            return (id) => state.group.find(p => p.id === id)
        }
    },
    actions: {
        async loadGroups() {
            this.loading = true;
            const url = `${config.backendUrl}/groups`;
            const resp = await performRequest(this,'GET', url, null);
            this.groups = resp.data.groups;
            this.loading = false;
        }
    }
});