<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> Multi Rule {{xnattest.Nat_TestName}}
                        <v-flex text-md-right>
                            <v-btn @click="deleteData()" small color="error">Hapus</v-btn>
                            <v-btn @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="xextremelow" label="Extreme Low" hide-details></v-text-field>
                                </v-flex>
                                <v-flex xs6 pa-1>
                                    <v-text-field v-model="xlinieritas" label="Linieritas" hide-details></v-text-field>
                                </v-flex>
                            </v-layout>
                            <v-layout row>
                                <v-flex xs6 pa-1>
                                    <v-text-field v-model="xextremehigh" label="Extreme High" hide-details></v-text-field>
                                </v-flex>
                                <v-flex xs6 pa-1>
                                    <v-text-field v-model="xlimitdetection" label="Limit Detection" hide-details></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: {
            xnattest() {
                return this.$store.state.multirule.selected_multirule
            },
            dialogconfirmationdelete: {
                get() {
                    return this.$store.state.multirule.dialog_confirmation_delete
                },
                set(val) {
                    this.$store.commit("multirule/update_dialog_confirmation_delete", val)
                }
            },
            msgconfirmationdelete() {
                return this.$store.state.multirule.msg_confirmation_delete
            },
            xact() {
                return this.$store.state.multirule.act
            },
            detail() {
                return this.$store.state.multirule.selected_multirule
            },
            xextremelow: {
                get() {
                    return this.$store.state.multirule.extremelow
                },
                set(val) {
                    this.$store.commit("multirule/update_extremelow", val)
                    this.$store.commit("multirule/update_no_save", 1)
                }
            },
            xextremehigh: {
                get() {
                    return this.$store.state.multirule.extremehigh
                },
                set(val) {
                    this.$store.commit("multirule/update_extremehigh", val)
                    this.$store.commit("multirule/update_no_save", 1)
                }
            },
            xlinieritas: {
                get() {
                    return this.$store.state.multirule.linieritas
                },
                set(val) {
                    this.$store.commit("multirule/update_linieritas", val)
                    this.$store.commit("multirule/update_no_save", 1)
                }
            },
            xlimitdetection: {
                get() {
                    return this.$store.state.multirule.limitdetection
                },
                set(val) {
                    this.$store.commit("multirule/update_limitdetection", val)
                    this.$store.commit("multirule/update_no_save", 1)
                }
            },
        },
        methods: {
            checkError(value) {
                var errors = this.$store.state.multirule.errors
                if (errors.includes(value)) {
                    return true
                } else {
                    return false
                }
            },
            saveData() {
                var prm = {}
                prm.xid = this.$store.state.multirule.selected_multirule.xid
                prm.Nat_MultiRuleID = this.$store.state.multirule.selected_multirule.Nat_MultiRuleID
                prm.Nat_MultiRuleNat_TestID = this.xnattest.Nat_TestID
                prm.Nat_MultiRuleExtremeLow = this.xextremelow
                prm.Nat_MultiRuleExtremeHigh = this.xextremehigh
                prm.Nat_MultiRuleLinieritas = this.xlinieritas
                prm.Nat_MultiRuleLimitDetection = this.xlimitdetection
                this.$store.dispatch("multirule/save", prm)

            },
            saveNewMultiRule() {
                var prm = {}
                prm.Nat_MultiRuleID = 0
                prm.Nat_MultiRuleNat_TestID = this.$store.state.multirule.selected_multirule.Nat_MultiRuleNat_TestID
                prm.Nat_MultiRuleExtremeLow = this.xextremelow
                prm.Nat_MultiRuleExtremeHigh = this.xextremehigh
                prm.Nat_MultiRuleLinieritas = this.xlinieritas
                prm.Nat_MultiRuleLimitDetection = this.xlimitdetection
                this.$store.dispatch("multirule/newmultirule", prm)
            },
            deleteData() {
                let msg = "Yakin, akan menghapus data " + this.xnattest.Nat_TestName + " ?"
                this.$store.commit("multirule/update_msg_confirmation_delete", msg)
                this.$store.commit("multirule/update_dialog_confirmation_delete", true)
            },
            doDeleteData() {
                var prm = {}
                prm.Nat_MultiRuleID = this.$store.state.multirule.selected_multirule.Nat_MultiRuleID
                prm.testid = this.xnattest.Nat_TestID
                prm.isquantitative = this.xnattest.Nat_TestIsQuantitative
                this.$store.dispatch("multirule/delete", prm)
            }
        }
    }
</script>