<template>
   <v-layout class="fill-height" column>
      <v-card   class="mb-2 pa-2 searchbox">
         <v-layout row>
            <v-flex xs12>
               <v-layout>
                  <v-text-field class="flex xs4 ma-1"
                                placeholder="No Lab"
                                single-line
                                outline
                                hide-details
                                v-model="nolab"
                                @keyup.native="keySearch"
                                ></v-text-field>
                     <v-text-field class="flex xs8 ma-1"
                                   label=""
                                   placeholder="Nama"
                                   single-line
                                   outline
                                   hide-details
                                   v-model="search"
                                   @keyup.native="keySearch"
                                   ></v-text-field>

                    <v-btn class="mr-1 ml-1 one-btn-icon fz-2" color="success" @click="search_patient" large block fill-height >
                        <span class="icon-search"></span>
                    </v-btn>
                    <v-btn class="mr-1 ml-1 one-btn-icon fz-2" color="info" @click="send" large block fill-height >
                        <v-icon>send</v-icon>
                    </v-btn>
               </v-layout>
            </v-flex>
            <!-- <v-flex xs4>
               <v-layout>
                  <v-btn class="flex xs6 ma-1" color="success" @click="search_patient" >
                     Search
                  </v-btn>
                     <v-btn class="flex xs6 ma-1" color="info" @click="send" >
                        Kirim
                     </v-btn>
               </v-layout>
            </v-flex> -->
         </v-layout>
      </v-card>


      <v-card class="grow">
         <v-subheader>
            <h3 class="title">SPECIMEN SIAP KIRIM</h3>
         </v-subheader>
         <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" 
                   @click="select(props.item)">
                  {{ oneMoment(props.item.date)}}
               </td>
               <td class="text-xs-left pa-2" 
                   @click="select(props.item)">
                  {{ props.item.lab }}
               </td>
               <td class="pa-2" 
                   @click="select(props.item)">
                  {{ props.item.sid}}
               </td>
               <td class="text-xs-left pa-2" 
                   @click="select(props.item)">
                  {{ props.item.name }}
               </td>
               <td class="text-xs-left pa-2" 
                   @click="select(props.item)">
                  <v-checkbox :value="props.item.id" v-model="ids" hide-details></v-checkbox>
               </td>
            </template>

         </v-data-table>

      </v-card>
   </v-layout>
</template>

<style scoped>
.fz-2 {
    font-size: 1.5em
}

.v-btn--large {
    height: 52px;
}
</style>

<script>
module.exports = {
   data() {
      return {
         query: "",
         items: [],
         headers: [
            {
               text: "SAMPLING",
               align: "left",
               sortable: false,
               value: "mr",
               width: "15%",
               class: "pa-2 blue lighten-3 white--text"
            },
            {
               text: "NO LAB",
               align: "left",
               sortable: false,
               value: "mr",
               width: "15%",
               class: "pa-2 blue lighten-3 white--text"
            },
            {
               text: "SAMPLE ID",
               align: "left",
               sortable: false,
               value: "lab",
               width: "15%",
               class: "pa-2 blue lighten-3 white--text"
            },
            {
               text: "NAMA",
               align: "left",
               sortable: false,
               value: "name",
               width: "25%",
               class: "pa-2 blue lighten-3 white--text"
            },

            {
               text: "Pilih",
               align: "left",
               sortable: false,
               value: "status",
               width: "5%",
               class: "pa-2 blue lighten-3 white--text"
            }
         ],
         isLoading: false,
         // patients: [
         //    {"status":"","date":"2019-02-21 10:00:00",
         //       "lab":"08000198909", "sid": "08000198909-S", 
         //       "name": "Pasien Umum", "selected":false},
         //    {"status":"","date":"2019-02-22 06:30:00",
         //       "lab":"08000198111", "sid": "08000198111-2", 
         //       "name": "Heri Suryawan", "selected":false},
         //    {"status":"","date":"2019-02-22 06:45:00",
         //       "lab":"08000198222", "sid": "08000198222-U", 
         //       "name": "LUKA MODRIC","selected":true},
         // ]
      };
   },
   methods : {
      oneMoment : function(d) {
         return window.oneMoment(d)
      },

      search_patient () {
         this.$store.dispatch('handling_patient/search')
      },

      send () {
         this.$store.dispatch('handling_patient/send')
      },

      select(item) {
         this.$store.commit('handling_patient/update_selected_patient', item)
      },

      keySearch(e) {
          if (e.which == 13) {
              this.search_patient()
          }
      }
   },
   computed : {
      patients () {
         return this.$store.state.handling_patient.patients
      },

      nolab : {
         get () {
            return this.$store.state.handling_patient.nolab
         },
         set (v) {
            this.$store.commit('handling_patient/update_nolab', v)
         }
      },

      search : {
         get () {
            return this.$store.state.handling_patient.search
         },
         set (v) {
            this.$store.commit('handling_patient/update_search', v)
         }
      },

      ids : {
         get () {
            return this.$store.state.handling_patient.ids
         },
         set (v) {
            this.$store.commit('handling_patient/update_ids', v)
         }
      }
   }
}
</script>
