<template>
    <div>
        <v-layout class="mb-2 " column>
            <v-card height="650px" class="pb-0">
                <v-toolbar class="mb-2" dense>

                    <v-toolbar-title style="text-align:center!important" class="title">ANAMNESE</v-toolbar-title>

                    <v-spacer></v-spacer>

                </v-toolbar>
                <v-layout v-for="(action,index) in button_actions" :key="index" row>
                    <v-flex class="pl-2 pr-2 pb-2" xs12>
                        <v-btn v-if="selected_action.id !== action.id" @click="changeButton(action)" block outline large>{{action.name}}</v-btn>
                        <v-btn v-if="selected_action.id === action.id" @click="changeButton(action)" color="primary" small block depressed large>{{action.name}}</v-btn>
                    </v-flex>
                </v-layout>
                <v-divider class="mt-2 mb-2"></v-divider>
                <v-card-actions>
                    <v-btn v-if="!_.isEmpty(selected_patient) && selected_patient.orderIsAnamnese === 'Y'" @click="endSession()" block style="min-height:45px" color="red lighten-2" dark>SELESAI</v-btn>
                </v-card-actions>
            </v-card>
        </v-layout>
        
    </div>
</template>

<style scoped>
.div_bottom {
    position: absolute;
right:    0;
bottom:   0;
}
</style>

<script>
module.exports = {
    data: () => ({

    }),
    computed: {
        selected_patient: {
            get() {
                return this.$store.state.patient.selected_patient
            },
            set(val) {
                this.$store.commit("patient/update_selected_patient", val)
            }
        },
        button_actions() {

        return this.$store.state.patient.button_actions
        },
        selected_action: {
            get() {
                return this.$store.state.patient.selected_action
            },
            set(val) {
                this.$store.commit("patient/update_selected_action", val)
            }
        },
        pgrs_save() {

            return this.$store.state.patient.pgrs_save
        },
        active() {
            return this.$store.state.button_active
        },
        dialogconfirmationdelete: {
            get() {
                return this.$store.state.patient.dialog_confirmation_delete
            },
            set(val) {
                this.$store.commit("patient/update_dialog_confirmation_delete", val)
            }
        }
    },
    methods: {
        endSession(){
            this.$store.dispatch("patient/endsession",this.selected_patient)
        },
        changeButton(XX) {
            this.selected_action = XX
            var x = XX.id
            //  this.active = x;
            this.$store.commit('change_button', x);
            console.log(x)
            if(x == '01'){
                this.$store.commit("patient/update_active_name", 'KELUHAN UTAMA')
                this.$store.commit("patient/update_xnote", this.$store.state.patient.selected_patient.KeluhanUtamaText)
            }
            if(x == '02'){
                console.log(this.$store.state.patient.selected_patient.RiwayatPenyakitDahuluText)
                this.$store.commit("patient/update_active_name", 'RIWAYAT PENYAKIT & ALERGI DAHULU')
                this.$store.commit("patient/update_xnote", this.$store.state.patient.selected_patient.RiwayatPenyakitDanAlergiDahuluText)
            }
            if(x == '03'){
                this.$store.commit("patient/update_active_name", 'RIWAYAT PENYAKIT & ALERGI SEKARANG')
                this.$store.commit("patient/update_xnote", this.$store.state.patient.selected_patient.RiwayatPenyakitDanAlergiSekarangText)
            }
            if(x == '04'){
                this.$store.commit("patient/update_active_name", 'RIWAYAT PENYAKIT KELUARGA')
                this.$store.commit("patient/update_xnote", this.$store.state.patient.selected_patient.RiwayatPenyakitKeluargaText)
            }
            if(x == '05'){
                this.$store.commit("patient/update_active_name", 'RIWAYAT PENGOBATAN')
                this.$store.commit("patient/update_xnote", this.$store.state.patient.selected_patient.RiwayatPengobatanText)
            }
            if(x == '06'){
                this.$store.commit("patient/update_active_name", 'RIWAYAT SOSIAL')
                this.$store.commit("patient/update_xnote", this.$store.state.patient.selected_patient.RiwayatSosialText)
            }
            if(x == '07'){
                this.$store.commit("patient/update_active_name", 'RIWAYAT OPERASI')
                this.$store.commit("patient/update_xnote", this.$store.state.patient.selected_patient.RiwayatOperasiText)
            }
            if(x == '09'){
                this.$store.commit("patient/update_active_name", 'RIWAYAT VAKSIN / IMUNISASI')
                this.$store.commit("patient/update_xnote", this.$store.state.patient.selected_patient.RiwayatImunisasiText)
            }
            //alert(this.active);
        },
        checkError(value) {
            var errors = this.$store.state.patient.errors
            if (errors.includes(value)) {
                return true
            } else {
                return false
            }
        }
    }
}
</script>