<template>
    <v-dialog v-model="dialog_confirm_item" persistent width="40vw">
        <v-card>
            <v-card-title class="headline grey lighten-2">Konfirmasi Hapus</v-card-title>
            <v-card-text>
                <v-layout row wrap>
                    <v-flex xs12>
                        <p>
                            Apakah anda yakin akan menghapus data mapping item coa inventaris golongan
                            : <strong>{{ selected_inventaris_item.M_ItemDesc }}</strong> ?
                        </p>
                    </v-flex>
                </v-layout>
            </v-card-text>
            <v-card-actions>
                <v-spacer></v-spacer>
                <v-btn @click="batal()" color="error" class="white--text">Batal</v-btn>
                <v-btn @click="konfirmasi()" color="primary" class="white--text">Konfirmasi</v-btn>
            </v-card-actions>
        </v-card>
    </v-dialog>
</template>

<script>
module.exports = {
    data() {
        return {}
    },
    computed: {
        dialog_confirm_item: {
            get() {
                return this.$store.state.invItemMap.dialog_confirm_item;
            },
            set(val) {
                this.$store.commit("invItemMap/update_dialog_confirm_item", val);
            }
        },
        selected_inventaris_item: {
            get() {
                return this.$store.state.invItemMap.selected_inventaris_item;
            },
            set(val) {
                this.$store.commit("invItemMap/update_selected_inventaris_item", val);
            }
        },
        loading_process() {
            return this.$store.state.invMap.loading_process;
        }
    },
    methods: {
        checkEmpty(obj) {
            return obj && Object.keys(obj).length === 0 && obj.constructor === Object;
        },
        batal() {
            this.selected_inventaris_item = {};
            this.dialog_confirm_item = false;
        },
        konfirmasi() {
            if (!this.loading_process) {
                const itm = this.selected_inventaris_item;
               
                this.$store.dispatch("invItemMap/deleteInvItemCoaMapping", {
                    M_InventarisItemCoaMappingID: itm.itemCoaMapID
                })
            } else {
                const snac = { state: true, msg: "terdapat proses masih berjalan", color: "warning" };
                this.$store.commit('invMap/update_snackbar', snac);
            }
        }
    }
}
</script>
