<template>
   <v-layout class="fill-height" column>
      <v-card class="grow">
         <!-- <v-subheader>
            <h3 class="title">DAFTAR PASIEN</h3>
         </v-subheader> -->
            <hr style="border-top:0px solid #c8c8c8;" />
         <v-data-table
            :headers="headers" :items="patients"
            :loading="isLoading"
            hide-actions class="xelevation-1">
            <template slot="items" slot-scope="props">
               <td class="text-xs-left pa-2 green--text" v-bind:class="is_selected(props.item)"
                   @click="select(props.item)">
                  {{ props.item.T_OrderHeaderLabNumber }}
               </td>
               <td class="text-xs-left pa-2" v-bind:class="is_selected(props.item)"
                   @click="select(props.item)">
                  {{ props.item.M_PatientName }}
               </td>
            </template>

         </v-data-table>
         <v-pagination
            v-model="curr_patient_page"
            :length="total_patient_page"
            :total-visible="5"
            @input="change_page"
         ></v-pagination>
      </v-card>
   </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 = {
   data() {
      return {
         query: "",
         items: [],
         headers: [
            {
               text: "NO LAB",
               align: "left",
               sortable: false,
               value: "mr",
               width: "30%",
               class: "pa-2 blue lighten-3 white--text"
            },
            {
               text: "NAMA",
               align: "left",
               sortable: false,
               value: "mr",
               width: "70%",
               class: "pa-2 blue lighten-3 white--text"
            }
         ],


         isLoading: false
      };
   },

   methods : {
      oneMoment : function(d) {
         return window.oneMoment(d)
      },

      select (item) {
         this.$store.commit('re_patient/update_selected_patient', item)
         this.$store.commit('re_px/update_id', item.T_OrderHeaderID)
         this.$store.dispatch('re_px/search')
         // this.$store.commit('ver_verification/update_selected_sent_sample', item)
      },

      is_selected (item) {
         let x = this.$store.state.re_patient.selected_patient
         if (!x)
            return ''
         
         if (x.T_OrderHeaderID == item.T_OrderHeaderID)
            return 'green lighten-4'

         return ''
      },

      change_page(x) {
         this.curr_patient_page = x
         this.$store.dispatch('re_patient/search')
      }
   },

   computed : {
      patients () {
         return this.$store.state.re_patient.patients
      },

      total_patient () {
         return this.$store.state.re_patient.total_patient
      },

      total_patient_page () {
         return this.$store.state.re_patient.total_patient_page
      },

      curr_patient_page : {
         get () { return this.$store.state.re_patient.curr_patient_page },
         set (v) { this.$store.commit('re_patient/update_curr_patient_page', v) }
      }
   },

   mounted () {
      this.$store.dispatch('re_patient/search')
   }
}
</script>
