<template>
    <div>
        <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 PEMERIKSAAN
                            <v-flex text-md-right>
                                <v-btn v-if="xact === 'new'" @click="saveNewTest()" small color="info">Simpan</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 wrap>
                            <v-flex xs12 pa-2>
                                <v-layout row>
                                    <v-flex xs6 pa-1>
                                        <v-text-field class="pr-1" v-model="xcode" label="Kode*"></v-text-field>
                                        <p style="margin-top: -14px;margin-right:2px;color:#fff" v-if="checkError('requirecode')" class="error pl-2 pr-2" style="color:#fff">Kode harus diisi ya</p>
                                        <p style="margin-top: -14px;margin-right:2px;color:#fff" v-if="checkError('requirecodeexist')" class="error pl-2 pr-2" style="color:#fff">Sudah dipake dong</p>
                                        <p style="margin-top: -14px;margin-right:2px;color:#fff" v-if="checkError('requirecodedigit')" class="error pl-2 pr-2" style="color:#fff">Kode harus 8 karakter</p>
                                    </v-flex>
                                    <v-flex xs6 pa-1>
                                        <v-text-field class="pr-1" v-model="xtestname" label="Nama*"></v-text-field>
                                        <p style="margin-top: -14px;margin-right:2px;color:#fff" v-if="checkError('requirename')" class="error pl-2 pr-2" style="color:#fff">Kalo gak ada namanya, bingung dong</p>
                                    </v-flex>
                                </v-layout>
                                <v-layout row>
                                    <v-flex xs4 pa-1>
                                        <v-text-field class="pr-1" v-model="xshortname" label="Singkatan"></v-text-field>
                                    </v-flex>
                                    <v-flex xs4 pa-1>
                                        <v-text-field class="pr-1" v-model="xnamebarcode" label="Kode bar" hint="Kode yang ditampilkan pada kode bar"></v-text-field>
                                    </v-flex>
                                    <v-flex xs4 pa-1>
                                        <v-text-field class="pr-1" v-model="xworklistname" label="Nama worklist"></v-text-field>
                                    </v-flex>
                                </v-layout>
                                <v-layout row>
                                    <v-flex xs4 pa-1>
                                        <v-select item-text="Nat_GroupName" return-object :items="xgroups" v-model="xgroup" label="Grup"></v-select>
                                        <p style="margin-top: -14px;margin-right:2px;color:#fff" v-if="checkError('requiregrup')" class="error pl-2 pr-2" style="color:#fff">Masukin grup dong</p>
                                    </v-flex>
                                    <v-flex xs4 pa-1>
                                        <v-select item-text="Nat_SubGroupName" return-object :items="xsubgroups" v-model="xsubgroup" label="Sub Grup"></v-select>
                                        <p style="margin-top: -14px;margin-right:2px;color:#fff" v-if="checkError('requiresubgrup')" class="error pl-2 pr-2" style="color:#fff">Subgrup-nya jangan lupa</p>
                                    </v-flex>
                                    <v-flex xs4 pa-1>
                                        <v-select item-text="Nat_SubSubGroupName" return-object :items="xsubsubgroups" v-model="xsubsubgroup" label="Sub Subgrup"></v-select>
                                    </v-flex>
                                </v-layout>
                                <v-layout row>
                                    <v-flex xs6 pa-1>
                                        <v-select readonly class="pr-1" item-text="Nat_TestTypeName" return-object :items="xtypes" v-model="xtype" label="Tipe"></v-select>
                                    </v-flex>
                                    <v-flex xs6 pa-1>
                                        <v-select class="pr-1" item-text="T_TestIsNonLab" return-object :items="xnonlabs" v-model="xnonlab" label="Tipe hasil"></v-select>
                                    </v-flex>
                                </v-layout>
                                <v-layout row>
                                    <v-flex v-bind:class="{ 'x6': xisresult === 'N','x3': xisresult === 'Y' && xflagquantitative === 'N','xs2': xisresult === 'Y'  && xflagquantitative === 'Y'}">
                                        <v-text-field class="pr-1" v-model="xfontsize" label="Ukuran huruf"></v-text-field>
                                    </v-flex>
                                    <v-flex v-bind:class="{ 'x6': xisresult === 'N','x3': xisresult === 'Y' && xflagquantitative === 'N','xs2': xisresult === 'Y' && xflagquantitative === 'Y' }">
                                        <v-text-field class="pr-1" v-model="xfontcolor" label="Warna huruf"></v-text-field>
                                    </v-flex>
                                    <v-flex xs1 v-if="xisresult === 'Y' && xflagquantitative === 'Y'">
                                        <v-text-field readonly class="pr-1" v-model="xflaglow" label="Low"></v-text-field>
                                    </v-flex>
                                    <v-flex xs1 v-if="xisresult === 'Y' && xflagquantitative === 'Y'">
                                        <v-text-field readonly class="pr-1" v-model="xflaghigh" label="High"></v-text-field>
                                    </v-flex>
                                    <!--<v-flex v-bind:class="{ 'x4': xisresult === 'N','x3': xisresult === 'Y' }">
                           <v-text-field
                              class="pr-1"
                              v-model="xflaggluc"
                              label="Flag gluc"
                              hide-details
                           ></v-text-field>
                        </v-flex>-->
                                    <v-flex v-if="xisresult === 'Y'" v-bind:class="{ 'xs4': xisresult === 'Y' && xflagquantitative === 'N','xs3': xisresult === 'Y' && xflagquantitative === 'Y' }">
                                        <v-autocomplete class="pr-1" label="Tipe Bahan" v-model="sampletypeaddress" :items="xsampletypees" :search-input.sync="search_sample"
                                            auto-select-first no-filter item-text="T_SampleTypeName" return-object no-data-text="Pilih jenis sample">
                                            <template slot="item" slot-scope="{ item }">
                                                <v-list-tile-content>
                                                    <v-list-tile-title v-text="item.T_SampleTypeName"></v-list-tile-title>
                                                </v-list-tile-content>
                                            </template>
                                        </v-autocomplete>
                                        <p style="margin-top: -14px;margin-right:2px;color:#fff" v-if="checkError('requiresample')" class="error pl-2 pr-2" style="color:#fff">Ada hasil, ada sample dong</p>
                                    </v-flex>
                                    <v-flex v-if="xisresult === 'Y'" v-bind:class="{ 'xs4': xisresult === 'Y' && xflagquantitative === 'N','xs3': xisresult === 'Y' && xflagquantitative === 'Y' }">
                                        <v-text-field class="pr-1" readonly v-model="xunit" label="Satuan"></v-text-field>
                                    </v-flex>
                                </v-layout>
                                <v-layout row>
                                    <v-flex xs6>
                                        <div>
                                            <v-btn @click="changeBtnFlagBold(xflagbold)" v-if="xflagbold === 'N'" small color="error">
                                                <v-icon left>close</v-icon> Huruf dibuat tebal</v-btn>
                                            <v-btn @click="changeBtnFlagBold(xflagbold)" v-if="xflagbold === 'Y'" small color="success">
                                                <v-icon left>check</v-icon> Huruf dibuat tebal</v-btn>
                                        </div>
                                        <div>
                                            <v-btn @click="changeBtnFlagItalic(xflagitalic)" v-if="xflagitalic === 'N'" small color="error">
                                                <v-icon left>close</v-icon> Huruf dibuat miring</v-btn>
                                            <v-btn @click="changeBtnFlagItalic(xflagitalic)" v-if="xflagitalic === 'Y'" small color="success">
                                                <v-icon left>check</v-icon> Huruf dibuat miring</v-btn>
                                        </div>
                                        <div>
                                            <v-btn @click="changeBtnFlagIsprice(xisprice)" v-if="xisprice === 'N'" small color="error">
                                                <v-icon left>close</v-icon> Bisa diberi harga</v-btn>
                                            <v-btn @click="changeBtnFlagIsprice(xisprice)" v-if="xisprice === 'Y'" small color="success">
                                                <v-icon left>check</v-icon> Bisa diberi harga</v-btn>
                                        </div>
                                        <div>
                                            <v-btn @click="changeBtnFlagPrintnote(xprintnote)" v-if="xprintnote === 'N' && xisprice === 'Y'" small color="error">
                                                <v-icon left>close</v-icon> Dicetak dinota</v-btn>
                                            <v-btn @click="changeBtnFlagPrintnote(xprintnote)" v-if="xprintnote === 'Y' && xisprice === 'Y'" small color="success">
                                                <v-icon left>check</v-icon> Dicetak dinota</v-btn>
                                        </div>
                                    </v-flex>
                                    <v-flex xs6 class="text-sm-right align-right">
                                        <div>
                                            <v-btn @click="changeBtnFlagIsresult(xisresult)" v-if="xisresult === 'N'" small color="error">
                                                <v-icon left>close</v-icon> Ada hasil</v-btn>
                                            <v-btn @click="changeBtnFlagIsresult(xisresult)" v-if="xisresult === 'Y'" small color="success">
                                                <v-icon left>check</v-icon> Ada hasil</v-btn>
                                        </div>
                                        <div>
                                            <v-btn @click="changeBtnFlagQuantitative(xflagquantitative)" v-if="xflagquantitative === 'N' && xisresult === 'Y'"
                                                small color="error">
                                                <v-icon left>close</v-icon> Hasil Kuantitatif</v-btn>
                                            <v-btn @click="changeBtnFlagQuantitative(xflagquantitative)" v-if="xflagquantitative === 'Y' && xisresult === 'Y'"
                                                small color="success">
                                                <v-icon left>check</v-icon> Hasil Kuantitatif</v-btn>
                                        </div>
                                        <div>
                                            <v-btn @click="changeBtnFlagDeltacheck(xdeltacheck)" v-if="xdeltacheck === 'N' && xisresult === 'Y'" small color="error">
                                                <v-icon left>close</v-icon> Delta check</v-btn>
                                            <v-btn @click="changeBtnFlagDeltacheck(xdeltacheck)" v-if="xdeltacheck === 'Y' && xisresult === 'Y'" small color="success">
                                                <v-icon left>check</v-icon> Delta check</v-btn>
                                        </div>
                                        <div>
                                            <v-btn @click="changeBtnFlagTrendanalysis(xtrendanalysis)" v-if="xtrendanalysis === 'N' && xisresult === 'Y'" small color="error">
                                                <v-icon left>close</v-icon> Trend Analysis</v-btn>
                                            <v-btn @click="changeBtnFlagTrendanalysis(xtrendanalysis)" v-if="xtrendanalysis === 'Y' && xisresult === 'Y'" small color="success">
                                                <v-icon left>check</v-icon> Trend Analysis</v-btn>
                                        </div>
                                        <div>
                                            <v-btn @click="changeBtnFlagPrintresult(xprintresult)" v-if="xprintresult === 'N' && xisresult === 'Y'" small color="error">
                                                <v-icon left>close</v-icon> Dicetak dihasil</v-btn>
                                            <v-btn @click="changeBtnFlagPrintresult(xprintresult)" v-if="xprintresult === 'Y' && xisresult === 'Y'" small color="success">
                                                <v-icon left>check</v-icon> Dicetak dihasil</v-btn>
                                        </div>
                                        <div>
                                            <v-btn @click="changeBtnFlagIsworklist(xisworklist)" v-if="xisworklist === 'N'" small color="error">
                                                <v-icon left>close</v-icon> Masuk worklist</v-btn>
                                            <v-btn @click="changeBtnFlagIsworklist(xisworklist)" v-if="xisworklist === 'Y'" small color="success">
                                                <v-icon left>check</v-icon> Masuk worklist</v-btn>
                                        </div>
                                      <!--  <div>
                                            <v-btn @click="changeBtnFlagIslongresult(xislongresult)" v-if="xislongresult === 'N'" small color="error">
                                                <v-icon left>close</v-icon> Long Result</v-btn>
                                            <v-btn @click="changeBtnFlagIslongresult(xislongresult)" v-if="xislongresult === 'Y'" small color="success">
                                                <v-icon left>check</v-icon> Long Result</v-btn>
                                        </div> -->
                                    </v-flex>
                                </v-layout>
                            </v-flex>
                        </v-layout>
                    </v-flex>
                    </v-flex>
            </v-card>
            </v-layout>


            <template>

                <v-dialog v-model="dialogerrormsg" max-width="30%">
                    <v-card>
                        <v-card-title class="headline red en-1 pt-2 pb-2" primary-title>
                            <h4 style="color:#FFEBEE">Peringatan !</h4>
                        </v-card-title>
                        <v-card-text class="pt-2 pb-2">
                            <v-layout row>
                                <v-flex xs12 d-flex>
                                    <v-layout row>
                                        <v-flex pb-1 xs12>
                                            <v-layout row>
                                                <v-flex pt-2 pr-2 v-html="errormsg" xs12>

                                                </v-flex>
                                            </v-layout>
                                        </v-flex>
                                    </v-layout>
                                </v-flex>
                            </v-layout>
                        </v-card-text>
                        <v-divider></v-divider>
                        <v-card-actions>
                            <v-spacer></v-spacer>

                            <v-btn color="error" flat @click="dialogerrormsg = false">
                                Tutup
                            </v-btn>
                        </v-card-actions>
                    </v-card>
                </v-dialog>

            </template>
    </div>
</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: () => ({
            dialogerrormsg: false,
            errormsg: '',
            search_sample: '',
            startdate: '',
            enddate: '',
            menustartdate: false,
            menuenddate: false,
            date: new Date().toISOString().substr(0, 10)
        }),
        computed: {
            dialogconfirmationdelete: {
                get() {
                    return this.$store.state.test.dialog_confirmation_delete
                },
                set(val) {
                    this.$store.commit("test/update_dialog_confirmation_delete", val)
                }
            },
            msgconfirmationdelete() {
                return this.$store.state.test.msg_confirmation_delete
            },
            isLoading() {
                return this.$store.state.test.search_status == 1
            },
            xact() {
                return this.$store.state.test.act
            },
            detail() {
                return this.$store.state.test.selected_test
            },
            xtypes() {
                return this.$store.state.test.types
            },
            xtype: {
                get() {
                    return this.$store.state.test.selected_type
                },
                set(val) {
                    this.$store.commit("test/update_selected_type", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xnonlabs() {
                return this.$store.state.test.nonlabs
            },
            xnonlab: {
                get() {
                    return this.$store.state.test.selected_nonlab
                },
                set(val) {
                    this.$store.commit("test/update_selected_nonlab", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xtestname: {
                get() {
                    return this.$store.state.test.test_name
                },
                set(val) {
                    this.$store.commit("test/update_test_name", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xnamebarcode: {
                get() {
                    return this.$store.state.test.namebarcode
                },
                set(val) {
                    this.$store.commit("test/update_namebarcode", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xdob: {
                get() {
                    return this.$store.state.test.dob
                },
                set(val) {
                    this.$store.commit("test/update_dob", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xgroups() {
                return this.$store.state.test.groups
            },
            xgroup: {
                get() {
                    return this.$store.state.test.selected_group
                },
                set(val) {
                    this.$store.commit("test/update_selected_group", val)
                    this.$store.commit("test/update_no_save", 1)
                    this.$store.dispatch("test/getsubgroup",{
                        groupid:val.Nat_GroupID
                    })
                }
            },
            xsubgroups() {
                return this.$store.state.test.subgroups
            },
            xsubgroup: {
                get() {
                    return this.$store.state.test.selected_subgroup
                },
                set(val) {
                    this.$store.commit("test/update_selected_subgroup", val)
                    this.$store.commit("test/update_no_save", 1)
                    this.$store.dispatch("test/getsubsubgroup",{
                        subgroupid:val.Nat_SubGroupID
                    })
                }
            },
            xsubsubgroups() {
                return this.$store.state.test.subsubgroups
            },
            xsubsubgroup: {
                get() {
                    return this.$store.state.test.selected_subsubgroup
                },
                set(val) {
                    this.$store.commit("test/update_selected_subsubgroup", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xreligions() {
                return this.$store.state.test.religions
            },
            xreligion: {
                get() {
                    return this.$store.state.test.selected_religion
                },
                set(val) {
                    this.$store.commit("test/update_selected_religion", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xcode: {
                get() {
                    return this.$store.state.test.code
                },
                set(val) {
                    this.$store.commit("test/update_code", val)
                    this.$store.dispatch("test/check_exist_code", {trx:this.$store.state.test.selected_test,newcode:val})
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xshortname: {
                get() {
                    return this.$store.state.test.shortname
                },
                set(val) {
                    this.$store.commit("test/update_shortname", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xunit: {
                get() {
                    return this.$store.state.test.unit
                },
                set(val) {
                    this.$store.commit("test/update_unit", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xflaglow: {
                get() {
                    return this.$store.state.test.flaglow
                },
                set(val) {
                    this.$store.commit("test/update_flaglow", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xflaghigh: {
                get() {
                    return this.$store.state.test.flaghigh
                },
                set(val) {
                    this.$store.commit("test/update_flaghigh", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xaddress: {
                get() {
                    return this.$store.state.test.address
                },
                set(val) {
                    this.$store.commit("test/update_address", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xsamples() {
                return this.$store.state.test.samples
            },
            xsample: {
                get() {
                    return this.$store.state.test.sample
                },
                set(val) {
                    this.$store.commit("test/update_sample", val)
                }
            },
            xsampletypees() {
                return this.$store.state.test.sampletypees
            },
            sampletypeaddress: {
                get() {
                    return this.$store.state.test.sampletype_address
                },
                set(val) {
                    this.$store.commit("test/update_sampletype_address", val)
                }
            },
            xpositions() {
                return this.$store.state.test.positions
            },
            xposition: {
                get() {
                    return this.$store.state.test.selected_position
                },
                set(val) {
                    this.$store.commit("test/update_selected_position", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xworklistname: {
                get() {
                    return this.$store.state.test.worklistname
                },
                set(val) {
                    this.$store.commit("test/update_worklistname", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xfontsize: {
                get() {
                    return this.$store.state.test.fontsize
                },
                set(val) {
                    this.$store.commit("test/update_fontsize", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xfontcolor: {
                get() {
                    return this.$store.state.test.fontcolor
                },
                set(val) {
                    this.$store.commit("test/update_fontcolor", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xmaxdiscount: {
                get() {
                    return this.$store.state.test.maxdiscount
                },
                set(val) {
                    this.$store.commit("test/update_maxdiscount", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xflagbold: {
                get() {
                    return this.$store.state.test.flagbold
                },
                set(val) {
                    this.$store.commit("test/update_flagbold", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xflagitalic: {
                get() {
                    return this.$store.state.test.flagitalic
                },
                set(val) {
                    this.$store.commit("test/update_flagitalic", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xflagquantitative: {
                get() {
                    return this.$store.state.test.flagquantitative
                },
                set(val) {
                    this.$store.commit("test/update_flagquantitative", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xdeltacheck: {
                get() {
                    return this.$store.state.test.deltacheck
                },
                set(val) {
                    this.$store.commit("test/update_deltacheck", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xtrendanalysis: {
                get() {
                    return this.$store.state.test.trendanalysis
                },
                set(val) {
                    this.$store.commit("test/update_trendanalysis", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xisresult: {
                get() {
                    return this.$store.state.test.isresult
                },
                set(val) {
                    this.$store.commit("test/update_isresult", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xisprice: {
                get() {
                    return this.$store.state.test.isprice
                },
                set(val) {
                    this.$store.commit("test/update_isprice", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xprintresult: {
                get() {
                    return this.$store.state.test.printresult
                },
                set(val) {
                    this.$store.commit("test/update_printresult", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xprintnote: {
                get() {
                    return this.$store.state.test.printnote
                },
                set(val) {
                    this.$store.commit("test/update_printnote", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xisworklist: {
                get() {
                    return this.$store.state.test.isworklist
                },
                set(val) {
                    this.$store.commit("test/update_isworklist", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            xislongresult: {
                get() {
                    return this.$store.state.test.islongresult
                },
                set(val) {
                    this.$store.commit("test/update_islongresult", val)
                    this.$store.commit("test/update_no_save", 1)
                }
            },
            startComputedDateFormatted() {
                return this.formatDate(this.xstartdate)
            },
            xstartdate: {
                get() {
                    return this.$store.state.test.startdate
                },
                set(val) {
                    this.$store.commit("test/update_startdate", val)
                }
            },
            endComputedDateFormatted() {
                return this.formatDate(this.xenddate)
            },
            xenddate: {
                get() {
                    return this.$store.state.test.enddate
                },
                set(val) {
                    this.$store.commit("test/update_enddate", val)
                }
            },
        },
        methods: {
            changeBtnFlagBold(value) {
                var newval = (value === 'Y') ? 'N' : 'Y'
                this.xflagbold = newval
            },
            changeBtnFlagItalic(value) {
                var newval = (value === 'Y') ? 'N' : 'Y'
                this.xflagitalic = newval
            },
            changeBtnFlagQuantitative(value) {
                var newval = (value === 'Y') ? 'N' : 'Y'
                this.xflagquantitative = newval
            },
            changeBtnFlagDeltacheck(value) {
                var newval = (value === 'Y') ? 'N' : 'Y'
                this.xdeltacheck = newval
            },
            changeBtnFlagTrendanalysis(value) {
                var newval = (value === 'Y') ? 'N' : 'Y'
                this.xtrendanalysis = newval
            },
            changeBtnFlagIsprice(value) {
                var newval = (value === 'Y') ? 'N' : 'Y'
                this.xisprice = newval
            },
            changeBtnFlagIsresult(value) {
                var newval = (value === 'Y') ? 'N' : 'Y'
                this.xisresult = newval
            },
            changeBtnFlagPrintresult(value) {
                var newval = (value === 'Y') ? 'N' : 'Y'
                this.xprintresult = newval
            },
            changeBtnFlagPrintnote(value) {
                var newval = (value === 'Y') ? 'N' : 'Y'
                this.xprintnote = newval
            },
            changeBtnFlagIsworklist(value) {
                var newval = (value === 'Y') ? 'N' : 'Y'
                this.xisworklist = newval
            },
            changeBtnFlagIslongresult(value) {
                var newval = (value === 'Y') ? 'N' : 'Y'
                this.xislongresult = newval
            },
            checkError(value) {
                var errors = this.$store.state.test.errors
                if (errors.includes(value)) {
                    return true
                } else {
                    return false
                }
            },
            saveData() {
                var prm = {}
                prm.T_TestID = this.$store.state.test.selected_test.T_TestID
                prm.T_TestNat_GroupID = this.$store.state.test.selected_group.Nat_GroupID
                prm.T_TestName = this.xtestname
                prm.T_TestNat_SubgroupID = this.$store.state.test.selected_subgroup.Nat_SubGroupID
                prm.T_TestNat_SubSubGroupID = this.$store.state.test.selected_subsubgroup.Nat_SubSubGroupID
                prm.T_TestShortName = this.xshortname
                prm.T_TestSasCode = this.xcode
                prm.T_TestShortNameBarcode = this.xnamebarcode
                prm.T_TestT_SampleTypeID = this.sampletypeaddress.T_SampleTypeID
                prm.T_TestWorklistName = this.xworklistname
                prm.T_TestFontSize = this.xfontsize
                prm.T_TestFontColor = this.xfontcolor
                prm.T_TestMaxDiscount = this.xmaxdiscount
                prm.T_TestIsNonLab = this.$store.state.test.selected_nonlab.T_TestIsNonLabID
                prm.T_TestIsBold = this.xflagbold
                prm.T_TestIsItalic = this.xflagitalic
                prm.T_TestIsQuantitative = this.xflagquantitative
                prm.T_TestIsDeltaCheck = this.xdeltacheck
                prm.T_TestIsTrendAnalysis = this.xtrendanalysis
                prm.T_TestIsResult = this.xisresult
                prm.T_TestIsPrice = this.xisprice
                prm.T_TestIsPrintResult = this.xprintresult
                prm.T_TestIsPrintNota = this.xisprice === 'N' ? 'N' : this.xprintnote
                prm.T_TestIsWorklist = this.xisworklist
                prm.T_TestIsLongResult = this.xislongresult
                this.$store.dispatch("test/save", prm)

            },
            saveNewTest() {
                var error_count = 0
                var error_msg = ''
                if (_.isEmpty(this.xgroup)) {
                    error_count++
                    error_msg +=
                        "<p><kbd class='text-uppercase'>Cabang</kbd> : Ayo, pilih salah satu cabang</p>"
                }

                if (this.xtestname === "") {
                    error_count++
                    error_msg +=
                        "<p><kbd class='text-uppercase'>Nama Karyawan</kbd> : Diisi dong nama karyawannya</p>"
                }

                if (_.isEmpty(this.xsubgroup)) {
                    error_count++
                    error_msg +=
                        "<p><kbd class='text-uppercase'>Jenis Kelamin</kbd> : Ayo, pilih salah satu jenis kelamin</p>"
                }

                if (this.xdob === "") {
                    error_count++
                    error_msg +=
                        "<p><kbd class='text-uppercase'>Tanggal Lahir</kbd> : Diisi dong tanggal lahirnya</p>"
                }



                var aDOB = moment(this.xdob, 'DD-MM-YYYY', true)
                var isValidDOB = aDOB.isValid()
                if (!isValidDOB) {
                    error_count++
                    error_msg +=
                        "<p><kbd class='text-uppercase'>Tanggal Lahir</kbd> : Diisi sesuai format dong (DD-MM-YYYY, contoh : 22-06-1988)</p>"
                }

                if (error_count > 0) {
                    this.errormsg = error_msg
                    this.dialogerrormsg = true
                } else {
                    var prm = {}
                    prm.T_TestID = 0
                    prm.T_TestNat_GroupID = this.$store.state.test.selected_group.Nat_GroupID
                    prm.T_TestName = this.xtestname
                    prm.T_TestDOB = this.xdob
                    prm.T_TestNat_SubgroupID = this.$store.state.test.selected_subgroup.Nat_SubGroupID
                    prm.T_TestNat_SubSubgroupID = this.$store.state.test.selected_subsubgroup.Nat_SubSubGroupID
                    prm.T_TestM_ReligionID = this.$store.state.test.selected_religion.M_ReligionID
                    prm.T_TestShortName = this.xshortname
                    prm.T_TestCode = this.xcode
                    prm.T_TestAddress = this.xaddress
                    prm.T_TestShortNameBarcode = this.xnamebarcode
                    prm.T_TestM_CityID = this.cityaddress.M_CityID
                    prm.T_TestT_SampleTypeID = this.sampletypeaddress.T_SampleTypeID
                    prm.T_TestM_PositionID = this.$store.state.test.selected_position.M_PositionID
                    prm.T_TestStartDate = this.xstartdate
                    prm.T_TestEndDate = this.xenddate
                    prm.T_TestWorklistName = this.xworklistname
                    prm.T_TestFontSize = this.xfontsize
                    prm.T_TestFontColor = this.xfontcolor
                    prm.T_TestMaxDiscount = this.xmaxdiscount
                    prm.T_TestIsBold = this.xisbold
                    this.$store.dispatch("test/newtest", prm)
                }
            },
            thr_search_sample: _.debounce(function () {
                this.$store.dispatch("test/searchsample", this.search_sample)
            }, 2000),
            formatDate(date) {
                if (!date) return null

                const [year, month, day] = date.split('-')
                return `${day}-${month}-${year}`
            },
            deFormatedDate(date) {
                if (!date) return null

                const [day, month, year] = date.split('-')
                return `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`
            },
            deleteData() {
                let msg = "Yakin, akan menghapus data pasien " + this.xtestname + " ?"
                this.$store.commit("test/update_msg_confirmation_delete", msg)
                this.$store.commit("test/update_dialog_confirmation_delete", true)
            },
            doDeleteData() {
                var prm = {}
                prm.T_TestID = this.$store.state.test.selected_test.T_TestID
                prm.T_TestName = this.xtestname
                this.$store.dispatch("test/delete", prm)
            }
        },
        watch: {
            search_sample(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.test.update_autocomplete_status == 1) return
                this.thr_search_sample()
            }
        }
    }
</script>
