<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">
            <tr :class="{
               'susulan' : is_susulan(props.item),
               'verif_done': is_verif_done(props.item), 'verif_partial': is_verif_partial(props.item), 
               'valid_done': is_valid_done(props.item), 'valid_partial':is_valid_partial(props.item), 
               'kirim_hasil': is_kirim(props.item) }"
            >
            <td 
                   class="text-xs-left pa-2 green--text" v-bind:class="[ is_cito(props.item)]"
                   @click="select(props.item)">
                   <span style="color:black">{{ props.item.T_OrderHeaderLabNumber }}</span><br/>
                   <span style="color:#660000">{{props.item.T_OrderHeaderLabNumberExt}}</span> 
               </td>
               <td 
                   class="text-xs-left pa-2" v-bind:class="[ is_cito(props.item)]"
                   @click="select(props.item)">
                  {{ props.item.M_PatientName }}<br/>
                   <span style="color:#660000">{{format_date(props.item.T_OrderHeaderDate)}}</span> 
                  <i aria-hidden="true" v-if="is_selected(props.item)" 
                     style="float:right; position:relative; top:-10px; right:50px;z-index:9"
                     class="v-icon material-icons theme--dark blue--text">pan_tool</i>
               </td>
            </tr>
           </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>
div.v-table__overflow {
   height:680px!important;
   overflow-y:scroll;
}
tr.susulan {
   background-image: linear-gradient(to right, rgba(255, 0, 0,0.9)  5%, white 5%);
}
tr.susulan.verif_partial{
   background-image: linear-gradient(to right, rgba(255, 0, 0,0.9)  5%, white 5%, white 40%,yellow 70%);
}
tr.susulan.verif_done {
   background-image: linear-gradient(to right, rgba(255, 0, 0,0.9)  5%, yellow 5%);
}
tr.susulan.verif_partial.valid_partial {
   background-image: linear-gradient(to right, rgba(255, 0, 0,0.9)  5%,#99e699 5%, #99e699 20%,white 30%,  white 70%, yellow 80%);
}
tr.susulan.verif_done.valid_partial {
   background-image: linear-gradient(to right, rgba(255, 0, 0,0.9)  5%,#99e699 5%,  #99e699 40%,yellow 60%);
}
tr.susulan.valid_done{
   background-image: linear-gradient(to right, rgba(255, 0, 0,0.9)  5%,#99e699 5%,  #99e699,#99e699, #99e699, #99e699);
}
tr.susulan.verif_partial.valid_partial.kirim_hasil {
   background-image: linear-gradient(to right, rgba(255, 0, 0,0.9)  5%,#99e699 5%, #99e699 20%,white 30%,  white 70%, yellow 80%,
      yellow 95%, #b800e6 95%);
}
tr.susulan.verif_done.valid_partial.kirim_hasil {
   background-image: linear-gradient(to right, rgba(255, 0, 0,0.9)  5%,#99e699 5%,  #99e699 40%,yellow 60%,
     yellow 95%, #b800e6 95% );
}
tr.susulan.verif_done.kirim_hasil {
   background-image: linear-gradient(to right, rgba(255, 0, 0,0.9)  5%,#99e699 5%,  #99e699 40%,yellow 60%,
     yellow 95%, #b800e6 95% );
}
tr.susulan.valid_done.kirim_hasil {
   background-image: linear-gradient(to right, rgba(255, 0, 0,0.9)  5%,#99e699 5%,  #99e699,#99e699, #99e699, #99e699,
     yellow 95%, #b800e6 95% );
}



tr.verif_partial{
   background-image: linear-gradient(to right, white 40%,yellow 70%);
}
tr.verif_done {
   background-image: linear-gradient(to right, yellow,yellow, yellow, yellow);
}
tr.verif_partial.valid_partial {
   background-image: linear-gradient(to right, #99e699 20%,white 30%,  white 70%, yellow 80%);
}
tr.verif_done.valid_partial {
   background-image: linear-gradient(to right, #99e699 40%,yellow 60%);
}
tr.valid_done{
   background-image: linear-gradient(to right, #99e699,#99e699, #99e699, #99e699);
}

tr.verif_partial.valid_partial.kirim_hasil {
   background-image: linear-gradient(to right, #99e699 20%,white 30%,  white 70%, yellow 80%,   yellow 95%, #b800e6 95% );
}
tr.verif_done.valid_partial.kirim_hasil {
   background-image: linear-gradient(to right, #99e699 40%,yellow 60%,   yellow 95%, #b800e6 95% );
}
tr.valid_done.kirim_hasil {
   background-image: linear-gradient(to right, #99e699,#99e699, #99e699, #99e699,   yellow 95%, #b800e6 95% );
}

.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 REG",
               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"
            }
         ],


      };
   },

   methods : {
      is_susulan(i) {
         let cur_date = moment().format('DD.MM.YYYY')
         let o_date = moment(i.T_OrderHeaderDate).format('DD.MM.YYYY')

         return cur_date != o_date
      },
      oneMoment : function(d) {
         return window.oneMoment(d)
      },
      is_cito (item) {
            let x = this.$store.state.re_patient.selected_patient
            if (!x)
               return ''
            
            if (item.T_OrderHeaderIsCito == "Y")
               return 'amber'

            return ''
      },
      is_kirim(i) {
         return i.T_OrderHeaderAddOnReadyPrint== 'P' || i.T_OrderHeaderAddOnReadyPrint == 'Y'
      },
      is_valid_partial(i) {
         return i.T_OrderHeaderAddOnValidationDone == 'P'  
      },
      is_valid_done(i) {
         return i.T_OrderHeaderAddOnValidationDone == 'Y'
      },
      is_verif_partial(i) {
         return i.T_OrderHeaderAddOnVerificationDone == 'P'
      },
      is_verif_done(i) {
         return i.T_OrderHeaderAddOnVerificationDone == 'Y'
      },
      format_date(p) {
         return moment(p).format("DD.MM.YYYY HH:mm")
      },
      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.dispatch('re_patient/info_req')
         // 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 false
         
         if (x.T_OrderHeaderID == item.T_OrderHeaderID)
            return true

         return false
      },

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

   computed : {
      isLoading() {
         return this.$store.state.re_patient.search_status == 1
      },
      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>
