<template>
   <v-layout class="fill-height" column>
      <v-card  class="mb-2 pa-2 searchbox" >
         <v-layout >

         <v-btn
              color="primary"
              @click="saveFavorite()"
          >
          KIRIM KE KASIR
          </v-btn>
         </v-layout>
      </v-card>
      <v-card >
         <v-layout row>
            <v-flex xs12 pl-2 pr-2 pt-2 pb-2>

            </v-flex>
         </v-layout>
      </v-card>
      <one-dialog-alert :status="openalertnopay" :msg="msgalertnopay" @forget-dialog-alert="forgetAlertNoPay()" @close-dialog-alert="closeAlertNoPay()"></one-dialog-alert>
   </v-layout>
</template>

<style scoped>
.cito {
   color: white;
   background-color:#FFC107;
}
.citoo {
   color: red;
}

span.xtd {
   margin-right:10px;
}
.searchbox .v-input.v-text-field .v-input__slot{
   min-height:40px;
}
.searchbox .v-btn {
   min-height:40px;
}
table.v-table tbody td,table.v-table tbody th {
   height: 40px;
}

table.v-table thead tr {
   height: 40px;
}

.v-messages{
   min-height:0px!important;
}

</style>

<script>
module.exports = {
components : {
      'one-dialog-info':httpVueLoader('../../common/oneDialogInfo.vue'),
      'one-dialog-alert':httpVueLoader('../../common/oneDialogAlert.vue')
   },
   mounted() {
      this.$store.dispatch("patient/search",{
            startdate:this.xstartdate,
            enddate:this.xenddate,
            search: this.searchnamelab,
            status: this.status.value,
            current_page:1,
            lastidx:0
         })
   },
   methods : {
   splittest(inp){
      let a_test = inp.split(',')
      let s_test = ''
      for(let i=0;i<a_test.length;i++) {
         let test = a_test[i]
         let a_cito = test.split('^')
         s_test += '<span class="xtd '
         if (a_cito[1] == 'Y') s_test += 'citoo'
         s_test += '" >'
         s_test += a_cito[0] + '</span>'
      }
      return s_test
   },
      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')}`
      },
      isSelected(p) {
         return p.T_OrderHeaderID == this.$store.state.patient.selected_patient.T_OrderHeaderID
      },
      isCito(p) {
         return p.cito== 1
      },
      searchPatient() {
         this.$store.dispatch("patient/search",{
            startdate:this.xstartdate,
            enddate:this.xenddate,
            search:this.searchnamelab,
            status: this.status.value,
            current_page:1,
            lastidx:0
         })
      },
      selectMe(pat) {
         let totpay = this.$store.state.payment.total_payment
         if(totpay === 0){
            let xobj = this.$store.state.payment.types
            xobj.forEach(function(obj){
               obj.leftvalue = 0
               obj.rightvalue = 0
            })
            this.$store.commit("payment/update_types",{records :xobj,total:xobj.length })
            this.$store.commit("patient/update_selected_patient",pat)
            this.$store.commit("payment/update_total_payment",0)
            this.$store.commit("payment/update_notes",pat.notes)
         }
         else{
            this.$store.commit("patient/update_open_alert_no_pay",true)
         }

      },
      closeAlertNoPay(){
          this.$store.commit("patient/update_open_alert_no_pay",false)
      },
      forgetAlertNoPay(){
          var xval = this.$store.state.payment.types
            var valpay = 0
            xval.forEach(function(obj){
                obj.leftvalue = 0
                obj.rightvalue = 0
            })
          this.$store.commit("payment/update_total_payment",0)
          this.$store.commit("patient/update_open_alert_no_pay",false)
      }
   },
   computed: {
      xstartdate:{
         get() {
               return this.$store.state.patient.start_date
         },
         set(val) {
               this.$store.commit("patient/update_start_date",val)
         }
      },
      xenddate:{
         get() {
               return this.$store.state.patient.end_date
         },
         set(val) {
               this.$store.commit("patient/update_end_date",val)
         }
      },
      searchnamelab:{
         get() {
               return this.$store.state.patient.search
         },
         set(val) {
               this.$store.commit("patient/update_search",val)
         }
      },
      statuses(){
         return this.$store.state.patient.statuses
      },
      status:{
         get() {
               return this.$store.state.patient.selected_status
         },
         set(val) {
               this.$store.commit("patient/update_selected_status",val)
         }
      },
      startDateFormatted () {
            return this.formatDate(this.xstartdate)
      },
      endDateFormatted () {
            return this.formatDate(this.xenddate)
      },
      isLoading() {
         return this.$store.state.patient.search_status == 1
      },
      patients() {
         return this.$store.state.patient.patients
      },
      openalertnopay:{
         get() {
               return this.$store.state.patient.open_alert_no_pay
         },
         set(val) {
               this.$store.commit("patient/update_open_alert_no_pay",false)
         }
      },
      msgalertnopay(){
         return this.$store.state.patient.msg_alert_no_pay
      },
      curr_page: {
         get() {
            return this.$store.state.patient.current_page
         },
         set(val) {
            this.$store.commit("patient/update_current_page",val)
            this.$store.dispatch("patient/search",{
                  startdate:this.xstartdate,
                  enddate:this.xenddate,
                  search: this.searchnamelab,
                  status: this.status.value,
                  current_page:val,
                  lastidx:0
            })
         }
      },
      xtotal_page: {
         get() {
            return this.$store.state.patient.total_page
         },
         set(val) {
            this.$store.commit("patient/update_total_page",val)
         }
      },
   },
   data() {
      return {
         items: [],
         menustartdate:false,
         menuenddate:false,
         headers: [
            {
               text: "TANGGAL",
               align: "left",
               sortable: false,
               value: "mr",
               width: "8%",
               class: "pa-2 blue lighten-3 white--text"
            },
            {
               text: "NOMOR",
               align: "left",
               sortable: false,
               value: "lab",
               width: "8%",
               class: "pa-2 blue lighten-3 white--text"
            } ,
            {
               text: "STATUS",
               align: "left",
               sortable: false,
               value: "status",
               width: "30%",
               class: "pa-2 blue lighten-3 white--text"
            } ,

            {
               text: "ACTION",
               align: "left",
               sortable: false,
               value: "status",
               width: "10%",
               class: "pa-2 blue lighten-3 white--text"
            }
         ],
      }
   }
}
</script>
