export default {

    state: () => ({
        pickingFor: null
    }),

    getters: {
        pickingFor(state) {
            return state.pickingFor;
        }
    },

    mutations: {
        setPickingFor(state, loop) {
            state.pickingFor = loop;
            if (loop != null) {
                loop.replacement = null;

            }
        },
        selectInsertForPicking(state, {scaffoldLoop, insertLoop}) {
            scaffoldLoop.replacement = insertLoop;
        }
    },

    actions: {
        pickFor(context, loop) {
            if (loop.id == context.getters.pickingFor?.id) {
                context.commit('setPickingFor', null);
            } else {
                context.commit('setPickingFor', loop);

            }
        },
        selectInsert(context, loop) {
            context.commit("selectInsertForPicking", {scaffoldLoop: context.getters.pickingFor, insertLoop: loop });
            context.commit("setPickingFor", null);
        },
        removeInsert(context, loop) {
            context.commit("selectInsertForPicking", {scaffoldLoop: loop, insertLoop: null});
            context.commit("setPickingFor", null);
        }
    }
}