<template>
   <v-layout class="fill-height" column>
      <v-card >
          <v-layout row>
             <v-flex xs12 pl-2 pr-2 pt-1>
                <v-btn block color="info">BUAT BARU</v-btn>
             </v-flex>
          </v-layout>
         <v-layout row>
            <v-flex xs12 pl-2 pr-2 pt-1 pb-2>
               <v-data-table 
                  :headers="headers" 
                  :items="xdetails"
                  :loading="isLoading"
                   hide-actions 
                   class="elevation-1">
                  <template slot="items" slot-scope="props">
                     <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':detailisSelected(props.item)}" @click="detailselectMe(props.item)">
                     <span class="flex body-2 font-weight-black">{{ props.item.T_TestConclusionName }}</span> </td>
                  </template>
               </v-data-table>
            </v-flex>
         </v-layout>
      </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 = {
   mounted() {
      this.$store.dispatch("sample/search",{
            search:this.xsearch,
            lastid:-1
         })
   },
   methods : {
      formatDate (date) {
         if (!date) return null

         const [year, month, day] = date.split('-')
         return `${day}-${month}-${year}`
      },
      deFormatedDate (date) {
          if (!date) return null

         const [ day,month, year] = date.split('-')
         return `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`
      },
      detailisSelected(p) {
         console.log(p)
         return p.T_TestConclusionID == this.$store.state.sample.selected_detail.T_TestConclusionID
      },
      searchTransaction() {
         this.$store.dispatch("sample/search",{
            search:this.xsearch,
            lastid:-1
         })
      },
      detailselectMe(detail) {
         console.log(detail)
         if(this.$store.state.sample.no_save == 0 ){
            this.$store.commit("sample/update_selected_detail",detail)
            this.$store.commit("sample/update_act",'edit')
           
         }else{
            this.$store.commit("sample/update_open_alert_confirmation",true)
         }
      },
      closeAlertConfirmation(){
          this.$store.commit("sample/update_open_alert_confirmation",false)
      },
      forgetAlertConfirmation(){
          this.$store.commit("sample/update_no_save",0)
          this.$store.commit("sample/update_open_alert_confirmation",false)
      },
      updateAlert_success(val){
         this.$store.commit("sample/update_alert_success",val)
      },
      setNewTransaction(){
         this.$store.commit("sample/update_selected_transaction",{})
         this.$store.commit("sample/update_details",[])
         this.$store.commit("sample/update_selected_detail",{})
         this.$store.commit("sample/update_selected_doctor",{})
         this.$store.commit("sample/update_selected_doctor_address",{})
         this.$store.commit("sample/update_selected_courier",{})
         this.$store.commit("sample/update_trx_date",moment(new Date()).format('YYYY-MM-DD'))
         this.$store.commit("sample/update_trx_note",'')
         this.$store.commit("sample/update_act",'new')
      },
      closeDialogSuccess(){
         let arrtrx = this.$store.state.sample.transactions
         var idx = _.findIndex(arrtrx, item => item.So_WalkLetterCourierID === this.$store.state.sample.last_id)
         //console.log(idx)
         this.$store.dispatch("sample/search",{
            startdate:this.xdatestart,
            enddate: this.xdateend,
            search:this.xsearch,
            stationid:this.xselectedstation.id,
            lastid:idx
         })
         this.$store.commit("sample/update_dialog_success",false)
      },
      closeDialogInfo(){
            this.$store.commit("sample/update_open_dialog_info",false)
            var trxs  = this.$store.state.sample.transactions
            var trx  = this.$store.state.sample.selected_transaction
            var idx = _.findIndex(trxs, item => item.T_OrderHeaderID === trx.T_OrderHeaderID &&  item.T_SampleTypeID === trx.T_SampleTypeID)
            this.$store.dispatch("sample/search",{
                startdate:this.xdatestart,
                enddate: this.xdateend,
                stationid:this.xselectedstation.id,
                lastid:idx
            })
          
      },
      selectgroup(value){
         this.selected_itemgroup = value
      },
      selectsubgroup(value){
         this.selected_itemsubgroup = value
      }
   },
   computed: {
      dialogsuccess: {
         get() {
            return this.$store.state.sample.dialog_success
         },
         set(val) {
            this.$store.commit("sample/update_dialog_success",val)
         }
      },
      msgsuccess(){
         return this.$store.state.sample.msg_success
      },
      snackbar: {
         get() {
            return this.$store.state.sample.alert_success
         },
         set(val) {
            this.$store.commit("sample/update_alert_success",val)
         }
      },
      isLoading() {
         return this.$store.state.sample.search_status == 1
      },
      itemgroups() {
         return this.$store.state.sample.item_groups
      },
      selected_itemgroupname() {
         return this.$store.state.sample.selected_itemgroupname
      },
      selected_itemgroup: {
         get() {
            //console.log(this.$store.state.sample.select_item_group)
            return this.$store.state.sample.select_item_group
         },
         set(val) {
            this.$store.commit("sample/update_select_item_group",val)
            this.$store.commit("sample/update_selected_itemgroupname",val.fulltitle)
            this.$store.commit("sample/update_item_subgroups",val.childrens)
            this.$store.commit("sample/update_select_item_subgroup",val.childrens[0])
            this.$store.commit("sample/update_selected_itemsubgroupname",val.childrens[0].fulltitle)
         }
      },
      itemsubgroups() {
         return this.$store.state.sample.item_subgroups
      },
      selected_itemsubgroupname() {
         return this.$store.state.sample.selected_itemsubgroupname
      },
      selected_itemsubgroup: {
         get() {
            return this.$store.state.sample.select_item_subgroup
         },
         set(val) {
            this.$store.commit("sample/update_select_item_subgroup",val)
             this.$store.commit("sample/update_selected_itemsubgroupname",val.fulltitle)
         }
      },
      xdatestart : {
         get() {
            return this.$store.state.sample.start_date
         },
         set(val) {
            this.$store.commit("sample/update_start_date",val)
         }
      },
      xdateend : {
         get() {
            return this.$store.state.sample.end_date
         },
         set(val) {
            this.$store.commit("sample/update_end_date",val)
         }
      },
      xsearch : {
         get() {
            return this.$store.state.sample.search
         },
         set(val) {
            this.$store.commit("sample/update_search",val)
         }
      },
      filterComputedDateFormattedStart () {
         return this.formatDate(this.xdatestart)
      },
      filterComputedDateFormattedEnd () {
         return this.formatDate(this.xdateend)
      },
      xstations() {
         return this.$store.state.sample.stations
      },
      xselectedstation: {
         get() {
            return this.$store.state.sample.selected_station
         },
         set(val) {
            this.$store.commit("sample/update_selected_station",val)
         }
      },
      xdetails() {
         return this.$store.state.sample.details
      },
      openalertconfirmation: {
         get() {
            return this.$store.state.sample.open_alert_confirmation
         },
         set(val) {
            this.$store.commit("sample/update_open_alert_confirmation",val)
         }
      },
      opendialoginfo: {
            get() {
                  return this.$store.state.sample.open_dialog_info
            },
            set(val) {
                  this.$store.commit("sample/update_open_dialog_info",false)
            }
      },
      msginfo(){
            return this.$store.state.sample.msg_info
      },
   },
   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: "NAMA KESIMPULAN",
               align: "center",
               sortable: false,
               width: "10%",
               class: "pa-2 blue lighten-3 white--text"
            }
         ]
      };
   }
}
</script>
