ItemView = {
    template: "#ItemView",
    router_path: "/ItemView",
    delimiters: ["[[", "]]"],
    props: [],

    computed: {
        ...Vuex.mapState({
            items: state => state.items.items,
            items_headers: state => state.items.headers,
            types: state => state.types.items,
            types_headers: state => state.types.headers,
        }),
    },

    methods: {

        item_edition (method, item) {
            return this.object_edit("items:edit", "items:create", 'items', method, item)
        },

        type_edition (method, item) {
            return this.object_edit("items:type.edit", "items:type.create", 'types', method, item)
        },

        async createItem (item) {
            const new_item = await this.item_edition("post", item)
            this.$store.commit("items/addItem", new_item)
        },

        async editItem (item) {
            const new_item = await this.item_edition("post", item)
            this.$store.commit("items/editItem", new_item)
        },
        
        async deleteItem (item) {
            await this.item_edition("delete", item)
            this.$store.commit("items/removeItem", item.id)
        },

        async createType (type) {
            const new_type = await this.type_edition("post", type)
            this.$store.commit("types/addItem", new_type)
        },

        async editType (type) {
            const new_type = await this.type_edition("post", type)
            this.$store.commit("types/editItem", new_type)
        },
        
        async deleteType (type) {
            await this.type_edition("delete", type)
            this.$store.commit("types/removeItem", type.id)
        },

    },
}
