<template>
    <v-dialog v-model="dialog_validation" persistent max-width="400">
        <v-card>
            <v-card-title class="headline">
                {{ selected_packet.T_PacketIsValidated == 'N' ? "Validasi Paket" : "Unvalidasi Paket" }}
            </v-card-title>
            <v-card-text>
                {{ 
                    selected_packet.T_PacketIsValidated == 'N' 
                    ? "Apakah anda yakin akan melakukan validasi paket berikut: " 
                    : "Apakah anda yakin akan melakukan unvalidasi paket berikut: " 
                }}
                
                <p class="mt-4 mb-0 p-0">Nama: {{ selected_packet.T_PacketName }}</p>
                <p class="m-0 p-0">Kode: {{ selected_packet.T_PacketSasCode }}</p>
            </v-card-text>
            <v-card-actions>
                <v-spacer></v-spacer>
                <v-btn
                    flat color="error darken-1"
                    @click="cancel()"
                >
                    Batal
                </v-btn>
                <v-btn
                    flat color="success darken-1"
                    @click="validate()"
                >
                    {{ selected_packet.T_PacketIsValidated == 'N' ? 'Validasi' : 'UnValidasi' }}
                </v-btn>
        </v-card-actions>
    </v-card>
    </v-dialog>
</template>


<script>
module.exports = {
    data() {
        return {
            
        }
    },
    computed: {
        dialog_validation: {
            get() {
                return this.$store.state.packet.dialog_validation
            },
            set(val) {
                this.$store.commit("packet/update_dialog_validation", val)
            }
        },
        selected_packet: {
            get() {
                return this.$store.state.packet.selected_packet
            },
            set(val) {
                this.$store.commit("packet/update_selected_packet", val)
            }
        }
    },
    methods: {
        cancel() {
            this.selected_packet = {}
            this.dialog_validation = false
        },
        validate() {
            const header = this.selected_packet
            if (header.T_PacketIsValidated == 'N') {
                this.$store.dispatch("packet/validatePacket");
            }

            if (header.T_PacketIsValidated == 'Y') {
                if (header.T_PacketValidatedCode) {
                    this.$store.dispatch("packet/unValidatePacket");
                }
                return
            }
        }
    },
}
</script>