import axios from "axios";

export default {
    namespaced: true,
    state: {
        campaignItem: {}
    },
    mutations: {
        setCampaignItem(state, campaignItem) {
            state.campaignItem = campaignItem;
        }
    },
    getters: {},
    actions: {
        getCampaignItem({ commit }, id) {
            axios
                .get(`/api/campaignItem/${id}`)
                .then(result => commit("setCampaignItem", result.data))
                .catch(console.error);
            console.log(JSON.stringify(result.data))
        },
        saveCampaign({ commit }, item) {
            axios
                .post("/api/campaignItem", item)
                .then(result => commit("setCampaignItem", result.data))
                .catch(console.error);
            console.log(JSON.stringify(item));
        },
        updateCampaign({ commit }, item) {
            axios
                .put("/api/campaignItem", item)
                .then(result => commit("setCampaignItem", item))
                .catch(console.error);
        }
    }
};
