<template>
    <v-layout class="mb-2" column>
        <v-dialog v-model="dialogconfirmationdelete" persistent max-width="290">
            <v-card>
                <v-card-title dark class="headline error pt-2 pb-2" primary-title style="color:white">
                    <h4 dark>Konfirmasi</h4>
                </v-card-title>
                <v-card-text>
                    {{msgconfirmationdelete}}
                </v-card-text>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn small color="error darken-1 text-sm-left" flat @click="doDeleteData()">Hapus</v-btn>
                    <v-btn small color="primary darken-1 text-sm-right" flat @click="dialogconfirmationdelete = false">Batal</v-btn>
                </v-card-actions>
            </v-card>
        </v-dialog>
        <v-card>
            <v-layout row>
                <v-flex xs12>
                    <v-subheader red--text text--lighten-1> DETAIL DAFTAR REKANAN
                        <v-flex text-md-right>
                            <v-btn v-if="xact === 'new'" @click="saveNewPatient()" small color="info">Simpan</v-btn>
                            <v-btn v-if="xact === 'edit'" @click="deleteData()" small color="error">Hapus</v-btn>
                            <v-btn v-if="xact === 'edit'" @click="saveData()" small color="primary">Simpan</v-btn>
                        </v-flex>
                    </v-subheader>
                    <v-divider></v-divider>
                    <v-layout row wrap>
                        <v-flex xs12 pa-2>
                            <v-layout row>
                                <v-flex xs6 pa-1>
                                <v-text-field v-model="xdob" label="Tanggal*" hint="format : DD-MM-YYYY , contoh : 22-06-1988"></v-text-field>
                                </v-flex>
                               <v-flex xs6 pa-1>
                                    <v-text-field v-model="xnorm" label="No Order"></v-text-field>
                                </v-flex>
                            </v-layout>
                            <v-layout row>
                               <v-flex xs12 pa-1>
                                    <v-text-field v-model="xnote" label="Catatan"></v-text-field>
                                </v-flex>
                            </v-layout>
                        </v-flex>
                    </v-layout>
                </v-flex>
                </v-flex>
        </v-card>
        </v-layout>
</template>

<style scoped>
    table,
    td,
    th {
        border: 1px solid #ddd;
        text-align: left;
    }

    table {
        border-collapse: collapse;
        width: 100%;
    }

    th,
    td {
        padding-top: 5px;
        padding-bottom: 5px;
        padding-left: 8px;
        padding-right: 5px;
    }

    .mini-input .v-input {
        margin-top: 0px;
    }

    .mini-input .v-input,
    .mini-input .v-input--selection-controls,
    .mini-input .v-input__slot {
        margin-top: 0px;
        margin-bottom: 0px;
        margin-left: 3px;
    }

    .mini-input .v-messages {
        min-height: 0px;
    }

    input.fhm-input {
        border: 1px solid black;
        border-radius: 2px;
        -webkit-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.1),
        0 0 4px rgba(0, 0, 0, 0.1);
        -moz-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.1),
        0 0 4px rgba(0, 0, 0, 0.1);
        box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.1),
        0 0 4px rgba(0, 0, 0, 0.1);
        padding: 2px 4px;
        background: rgba(255, 255, 255, 0.5);
        margin: 0 0 1px 0;
        width: 30px;
        text-align: center;
    }
</style>

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

        }),
        computed: {
            dialogconfirmationdelete: {
                get() {
                    return this.$store.state.patient.dialog_confirmation_delete
                },
                set(val) {
                    this.$store.commit("patient/update_dialog_confirmation_delete", val)
                }
            },
            msgconfirmationdelete() {
                return this.$store.state.patient.msg_confirmation_delete
            },
            xact() {
                return this.$store.state.patient.act
            },
            detail() {
                return this.$store.state.patient.selected_patient
            },
            xtitles () {
                return this.$store.state.patient.titles
            },
            xtitle: {
                get() {
                    return this.$store.state.patient.selected_title
                },
                set(val) {
                    this.$store.commit("patient/update_selected_title", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xpatientname: {
                get() {
                    return this.$store.state.patient.patient_name
                },
                set(val) {
                    this.$store.commit("patient/update_patient_name", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xnorm: {
                get() {
                    return this.$store.state.patient.norm
                },
                set(val) {
                    this.$store.commit("patient/update_norm", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xdob: {
                get() {
                    return this.$store.state.patient.dob
                },
                set(val) {
                    this.$store.commit("patient/update_dob", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xsexes() {
                return this.$store.state.patient.sexes
            },
            xsex: {
                get() {
                    return this.$store.state.patient.selected_sex
                },
                set(val) {
                    this.$store.commit("patient/update_selected_sex", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xreligions() {
                return this.$store.state.patient.religions
            },
            xreligion: {
                get() {
                    return this.$store.state.patient.selected_religion
                },
                set(val) {
                    this.$store.commit("patient/update_selected_religion", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xphone: {
                get() {
                    return this.$store.state.patient.phone
                },
                set(val) {
                    this.$store.commit("patient/update_phone", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xhp: {
                get() {
                    return this.$store.state.patient.hp
                },
                set(val) {
                    this.$store.commit("patient/update_hp", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xemail: {
                get() {
                    return this.$store.state.patient.email
                },
                set(val) {
                    this.$store.commit("patient/update_email", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xkartuidentitass() {
                return this.$store.state.patient.kartuidentitass
            },
            xkartuidentitas: {
                get() {
                    return this.$store.state.patient.selected_kartuidentitas
                },
                set(val) {
                    this.$store.commit("patient/update_selected_kartuidentitas", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xnoidentitas: {
                get() {
                    return this.$store.state.patient.noidentitas
                },
                set(val) {
                    this.$store.commit("patient/update_noidentitas", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
            xnote: {
                get() {
                    return this.$store.state.patient.note
                },
                set(val) {
                    this.$store.commit("patient/update_note", val)
                    this.$store.commit("patient/update_no_save", 1)
                }
            },
        },
        methods: {
            saveData() {
                var prm = {}
                prm.M_PatientID = this.$store.state.patient.selected_patient.M_PatientID
                prm.M_PatientM_TitleID = this.$store.state.patient.selected_title.M_TitleID
                prm.M_PatientName = this.xpatientname
                prm.M_PatientDOB = this.xdob
                prm.M_PatientM_SexID = this.$store.state.patient.selected_sex.M_SexID
                prm.M_PatientM_ReligionID = this.$store.state.patient.selected_religion.M_ReligionID
                prm.M_PatientEmail = this.xemail
                prm.M_PatientHP = this.xhp
                prm.M_PatientPhone = this.xphone
                prm.M_PatientM_IdTypeID = this.$store.state.patient.selected_kartuidentitas.M_IdTypeID
                prm.M_PatientIDNumber = this.xnoidentitas
                prm.M_PatientNote = this.xnote
                this.$store.dispatch("patient/save", prm)
            },
            saveNewPatient() {
                var prm = {}
                prm.M_PatientID = 0
                prm.M_PatientM_TitleID = this.$store.state.patient.selected_title.M_TitleID
                prm.M_PatientName = this.xpatientname
                prm.M_PatientDOB = this.xdob
                prm.M_PatientM_SexID = this.$store.state.patient.selected_sex.M_SexID
                prm.M_PatientM_ReligionID = this.$store.state.patient.selected_religion.M_ReligionID
                prm.M_PatientEmail = this.xemail
                prm.M_PatientHP = this.xhp
                prm.M_PatientPhone = this.xphone
                prm.M_PatientM_IdTypeID = this.$store.state.patient.selected_kartuidentitas.M_IdTypeID
                prm.M_PatientIDNumber = this.xnoidentitas
                prm.M_PatientNote = this.xnote
                this.$store.dispatch("patient/newpatient", prm)
            },
            deleteData() {
                let msg = "Yakin, akan menghapus data pasien " + this.xpatientname + " ?"
                this.$store.commit("patient/update_msg_confirmation_delete", msg)
                this.$store.commit("patient/update_dialog_confirmation_delete", true)
            },
            doDeleteData() {
                var prm = {}
                prm.M_PatientID = this.$store.state.patient.selected_patient.M_PatientID
                prm.M_PatientName = this.xpatientname
                this.$store.dispatch("patient/delete", prm)
            }
        }
    }
</script>