<template>
   <v-layout class="fill-height" column>
      <v-card class="grow">
            <hr style="border-top:0px solid #c8c8c8;" />
         <v-data-table
            :headers="headers" :items="pxs"
            :loading="isLoading"
            hide-actions class="xelevation-1">
            <template slot="items" slot-scope="props">
               <td class="text-xs-left pa-2 " :class="getClass(props.item)"
                   @click="select(props.item)">
                  {{ props.item.Nat_TestCode}}
               </td>
               <td class="text-xs-left pa-2" :class="getClass(props.item)"
                   @click="select(props.item)">
                  {{ props.item.Nat_TestName}}
               </td>
            </template>
         </v-data-table>
      </v-card>
   </v-layout>
</template>

<style scoped>
td.selected {
}
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: "KODE",
               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("list_px/update_selected_px",item)
         let sdate = this.$store.state.search_box.sdate
         let prm = { nat_test_id : item.Nat_TestID, sdate: sdate , token: window.one_token() }
         this.$store.dispatch("list_px/search_order",prm)
      },
      getClass(item) {
         let cls={ 'amber lighten-4' : false }
         if (item.Nat_TestID  == this.$store.state.list_px.selected_px.Nat_TestID ) {
            cls = { 'amber lighten-4' : true }
         }
         return cls
      },
   },
   computed : {
      pxs() {
         return this.$store.state.search_box.pxs
      }
   },
   mounted() {
      this.$store.dispatch("search_box/search_px")
   }
}
</script>
