<template>
   <v-layout class="fill-height" column>
      
      <v-card class="mb-2">
        <v-subheader red--text text--lighten-1> 
                KRITERIA
            <v-flex text-md-right>  
                <v-btn small @click="openDialogNormalValue()" color="warning">PILIH NILAI NORMAL</v-btn>
            </v-flex>
        </v-subheader>
        <v-divider></v-divider>
         <v-layout row>
            <v-flex xs12 pl-2 pr-2 pt-2 pb-2>
               <v-data-table 
                  :headers="headers" 
                  :items="xcriterias"
                  :loading="isLoading"
                  :pagination.sync="pagination"
                   class="elevation-1">
                  <template slot="items" slot-scope="props">
                     <td class="text-xs-center pa-2">
                       
                        <v-btn v-if="props.item.active === 'N'" style="min-width:auto" small color="error" dark><v-icon>close</v-icon></v-btn>
                        <v-btn v-if="props.item.active === 'Y'" style="min-width:auto" small color="success" dark><v-icon>check</v-icon></v-btn>
                        
                     </td>
                     <td class="text-xs-left pa-2" v-html="props.item.normalvalue_description">
                        
                     </td>
                     <td class="text-xs-center pa-2">
                        <v-btn @click="changeMinInclusive(props.item)" v-if="props.item.mininclusive === 'N'" small color="error">Tidak</v-btn>
                        <v-btn @click="changeMinInclusive(props.item)" v-if="props.item.mininclusive === 'Y'" small color="success">Ya</v-btn>
                     </td>
                     <td class="text-xs-center pa-2">
                         <v-text-field
                            hide-details
                            v-model="props.item.minvalue"
                            @change="changeMinValue(props.item.minvalue,props.item)"
                            solo
                            class="text-xs-center"
                            label="MIN"
                            outline
                        ></v-text-field>
                     </td>
                     <td class="text-xs-center pa-2">
                        <v-btn @click="changeMaxInclusive(props.item)" v-if="props.item.maxinclusive === 'N'" small color="error">Tidak</v-btn>
                        <v-btn @click="changeMaxInclusive(props.item)" v-if="props.item.maxinclusive === 'Y'" small color="success">Ya</v-btn>
                     </td>
                     <td class="text-xs-center pa-2">
                        <v-text-field
                            hide-details
                            v-model="props.item.maxvalue"
                            class="text-xs-center"
                            solo
                             @change="changeMaxValue(props.item.maxvalue,props.item)"
                            label="MAX"
                            outline
                        ></v-text-field>
                     </td>
                  </template>
                  <template>
                     <div class="text-xs-center">
                        <v-pagination
                           v-model="page"
                           :length="15"
                           :total-visible="7"
                        ></v-pagination>
                     </div>
                  </template>
               </v-data-table>
            </v-flex>
         </v-layout>
      </v-card>
      <v-card class="mb-2">
        <v-subheader red--text text--lighten-1> 
                KESIMPULAN
            <v-flex text-md-right>  
                <v-btn small color="warning">PILIH KESIMPULAN</v-btn>
            </v-flex>
        </v-subheader>
        <v-divider></v-divider>
         <v-layout row>
            <v-flex xs12 pl-2 pr-2 pt-2 pb-2>
               <v-textarea
                outline
                single-line
                hide-details
                name="input-7-4"
                label="Kesimpulan"
                value="The Woodman set to work at once, and so sharp was his axe that the tree was soon chopped nearly through."
                ></v-textarea>
            </v-flex>
         </v-layout>
      </v-card>
      <v-card >
         <v-subheader red--text text--lighten-1> 
                SARAN 
            <v-flex text-md-right>  
                <v-btn small color="warning">PILIH SARAN</v-btn>
            </v-flex>
        </v-subheader>
        <v-divider></v-divider>
         <v-layout row>
            <v-flex xs12 pl-2 pr-2 pt-2 pb-2>
               <v-textarea
                outline
                single-line
                hide-details
                name="input-7-4"
                label="Kesimpulan"
                value="The Woodman set to work at once, and so sharp was his axe that the tree was soon chopped nearly through."
                ></v-textarea>
            </v-flex>
         </v-layout>
      </v-card>
      <one-md-test-conclusion-dialog-normal-value></one-md-test-conclusion-dialog-normal-value>
    </v-layout>
</template>

<style scoped>
.searchbox .v-input.v-text-field .v-input__slot{
   min-height:60px;
}
.searchbox .v-btn {
   min-height:60px;
}
table.v-table tbody td,table.v-table tbody th {
   height: 40px;
}

table.v-table thead tr {
   height: 40px;
}

</style>

<script>
module.exports = {
   components : {
      'one-md-test-conclusion-dialog-normal-value':httpVueLoader('./oneMdTestConclusionDialogNormalValue.vue'),
      'one-dialog-alert':httpVueLoader('../../common/oneDialogAlert.vue')
   },
   methods : {
      openDialogNormalValue(){
         this.$store.commit("sample/update_dialog_normal_value",true)
      },
      changeMinInclusive(value){
            let arr = this.$store.state.sample.criterias
            var idx = _.findIndex(arr, item => item.id === value.id)
            arr[idx].mininclusive = value.mininclusive === 'N' ? 'Y':'N'
            this.$store.commit("sample/update_criterias",arr)
      },
      changeMaxInclusive(value){
            let arr = this.$store.state.sample.criterias
            var idx = _.findIndex(arr, item => item.id === value.id)
            arr[idx].maxinclusive = value.maxinclusive === 'N' ? 'Y':'N'
            this.$store.commit("sample/update_criterias",arr)
      },
      changeMinValue(val,value){
         let arr = this.$store.state.sample.criterias
            var idx = _.findIndex(arr, item => item.id === value.id)
            arr[idx].minvalue = val
            this.$store.commit("sample/update_criterias",arr)
      },
      changeMaxValue(val,value){
         let arr = this.$store.state.sample.criterias
            var idx = _.findIndex(arr, item => item.id === value.id)
            arr[idx].maxvalue = val
            this.$store.commit("sample/update_criterias",arr)
      }
   },
   computed: {
      isLoading() {
         return this.$store.state.sample.search_status == 1
      },
      xcriterias() {
         return this.$store.state.sample.criterias
      },
      xfiltermethode(){
         return this.$store.state.sample.filter_methodes
      },
      xselected_filter_methode:{
         get() {
               return this.$store.state.sample.selected_filter_methode
         },
         set(val) {
               this.$store.commit("form/update_selected_filter_methode",val)
         }
      },
   },
   data() {
      return {
         msgalertconfirmation:"Perubahan yang telah dilakukan belum disimpan dong !",
         menufilterdatestart:false,
         menufilterdateend:false,
         date: new Date().toISOString().substr(0, 10),
         items: [],
         name: '',
         page:1,
         headers: [
             {
               text: "",
               align: "center",
               sortable: false,
               width: "7%",
               class: "pa-2 blue lighten-3 white--text"
            },
            {
               text: "NILAI NORMAL",
               align: "left",
               sortable: false,
               width: "30%",
               class: "pa-2 blue lighten-3 white--text"
            },
            {
               text: "MIN INCLUSIVE",
               align: "center",
               sortable: false,
               width: "10%",
               class: "pa-2 blue lighten-3 white--text"
            },
            {
               text: "NILAI MIN",
               align: "center",
               sortable: false,
               width: "10%",
               class: "pa-2 blue lighten-3 white--text"
            },
             {
               text: "MAX INCLUSIVE",
               align: "center",
               sortable: false,
               width: "10%",
               class: "pa-2 blue lighten-3 white--text"
            },
            {
               text: "NILAI MAX",
               align: "center",
               sortable: false,
               width: "10%",
               class: "pa-2 blue lighten-3 white--text"
            }
            
         ],
         headers_search: [
            {
               text: "PASIEN",
               align: "left",
               sortable: false,
               width: "20%",
               class: "pa-2 blue lighten-3 white--text"
            },
            {
               text: "BARCODE",
               align: "center",
               sortable: false,
               width: "15%",
               class: "pa-2 blue lighten-3 white--text"
            },
            {
               text: "ALMARI",
               align: "left",
               sortable: false,
               width: "25%",
               class: "pa-2 blue lighten-3 white--text"
            },
            {
               text: "RAK",
               align: "center",
               sortable: false,
               width: "15%",
               class: "pa-2 blue lighten-3 white--text"
            },

            {
               text: "POSISI",
               align: "center",
               sortable: false,
               width: "10%",
               class: "pa-2 blue lighten-3 white--text"
            },
            {
               text: "AKSI",
               align: "center",
               sortable: false,
               width: "10%",
               class: "pa-2 blue lighten-3 white--text"
            }
         ],
         pagination:{
            descending: false,
            page: 1,
            rowsPerPage: 5,
            sortBy: 'trx_id ASC',
            totalItems: this.$store.state.sample.total_transactions
         }
      };
   }
}
</script>
