<template>
    <v-dialog v-model="dialog_confirm" 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 coa inventaris golongan
                            : <strong>{{ selected_inventaris_gol.M_InventarisGolName }}</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: {
            get() {
                return this.$store.state.invMap.dialog_confirm;
            },
            set(val) {
                this.$store.commit("invMap/update_dialog_confirm", val);
            }
        },
        selected_inventaris_gol: {
            get() {
                return this.$store.state.invMap.selected_inventaris_gol;
            },
            set(val) {
                this.$store.commit("invMap/update_selected_inventaris_gol", 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_gol = {};
            this.dialog_confirm = false;
        },
        konfirmasi() {
            if (!this.loading_process) {
                const inv = this.selected_inventaris_gol;
                this.$store.dispatch("invMap/deleteInventarisGolMapping", inv.M_InventarisCoaMappingID);
            } else {
                const snac = { state: true, msg: "terdapat proses masih berjalan", color: "warning" };
                this.$store.commit('invMap/update_snackbar', snac);
            }
        }
    }
}
</script>
