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

export const useStageStore = defineStore('stage', {
    state() {
        return {
            stagedChanges: false
        }
    },
    getters: {
        hasStagedChanges(state) {
            return state.stagedChanges;
        },
    },
    actions: {
        async checkStagedChanges() {
            const url = `${config.backendUrl}/properties/staged_changes`;
            const resp = await performRequest(this,'GET', url, null);
            this.stagedChanges = resp.data;
        },
        async applyChanges() {
            const url = `${config.backendUrl}/properties/staged_changes`;
            await performRequest(this, 'PUT', url, null, false);
            this.stagedChanges = false;
        }
    }

});