ItemTypeDetail = {
    template: "#ItemTypeDetail",
    router_path: "/ItemTypeDetail/:id",
    delimiters: ["[[", "]]"],

    computed: {
        object: function() {
            return this.$store.state.types.items.find(i => i.id == this.$route.params.id)
        },

        headers: function() {
            return this.$store.state.types.headers
        },

        all_items: function() {
            return this.$store.state.items.items.filter(i => i.type == this.$route.params.id)
        },

        items_headers: function() {
            return this.$store.state.items.headers
        },
    },

    methods: {

        item_edition (method, item) {
            return this.object_edit("items:edit", "items:create", "items", 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)
        },

    }
}
