<template>
  <div class="status-info">
    <el-form :inline="true" :model="basicInfo" class="demo-form-inline" size="small">
      <el-row>
        <el-col :span="6">
          <el-form-item label="Pending:">
            <span v-if="statusList.Submitted" style="color:#428bca">
              <router-link
                :to="{
                  path: `/trialStats?name=${basicInfo.FirstName+' '+basicInfo.LastName}&doctorId=${basicInfo.Id}&status=5&TokenKey=${tokenKey}`
                }"
                target="_blank"
                title="Pending client approval"
              >{{ statusList.Submitted }}</router-link>
            </span>
            <span v-else>{{ statusList.Submitted }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="Approved:">
            <span v-if="statusList.Approved" style="color:#428bca">
              <router-link
                :to="{
                  path: `/trialStats?name=${basicInfo.FirstName+' '+basicInfo.LastName}&doctorId=${basicInfo.Id}&status=8&TokenKey=${tokenKey}`
                }"
                target="_blank"
                title="Approved, waiting for training"
              >{{ statusList.Approved }}</router-link>
            </span>
            <span v-else>{{ statusList.Approved }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="Reading:">
            <span v-if="statusList.Reading" style="color:#428bca">
              <router-link
                :to="{
                  path: `/trialStats?name=${basicInfo.FirstName+' '+basicInfo.LastName}&doctorId=${basicInfo.Id}&status=10&TokenKey=${tokenKey}`
                }"
                target="_blank"
              >{{ statusList.Reading }}</router-link>
            </span>
            <span v-else>{{ statusList.Reading }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="On Vacation:">
            <span style="font-size:12px;margin-right:20px;">{{ holiday }}</span>
            <el-button
              type="text"
              size="small"
              @click="initHolidayList"
            >Planned Vacation</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-dialog
      title="Vacation"
      :visible.sync="dialogVisible"
      width="35%"
      :close-on-click-modal="false"
    >
      <el-table v-loading="loading" :data="list" size="small">
        <el-table-column type="index" />
        <el-table-column
          property="StartDate"
          label="Beginning Date"
          min-width="120"
          :formatter="beginTimeFormatter"
        />
        <el-table-column
          property="EndDate"
          label="End Date"
          min-width="120"
          :formatter="endTimeFormatter"
        />
      </el-table>
      <div class="pagination">
        <el-pagination
          background
          layout="total,sizes,prev, pager, next"
          :total="total"
          :page-sizes="[5, 10, 20, 50]"
          :page-size="pageSize"
          :current-page.sync="pageIndex"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        />
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getVacationList } from '@/api/reviewers'
import { fmtDate } from '@/utils/formatter'
import { getToken } from '@/utils/auth'
export default {
  props: {
    basicInfo: {
      type: Object,
      default() {
        return {}
      }
    },
    statusList: {
      type: Object,
      default() {
        return {}
      }
    },
    doctorId: {
      type: String,
      default: ''
    },
    holiday: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      list: [],
      total: 0,
      dialogVisible: false,
      loading: false,
      pageIndex: 1,
      pageSize: 10,
      tokenKey: getToken()
    }
  },
  methods: {
    initHolidayList() {
      this.dialogVisible = true
      this.loading = true
      getVacationList(this.doctorId, this.pageIndex, this.pageSize)
        .then(res => {
          if (res.IsSuccess) {
            this.list = res.Result.CurrentPageData
            this.total = res.Result.TotalCount
          }
          this.loading = false
        })
        .catch(() => {
          this.loading = false
        })
    },
    beginTimeFormatter(row) {
      if (row.StartDate) {
        return fmtDate(row.StartDate)
      }
    },
    endTimeFormatter(row) {
      if (row.EndDate) {
        return fmtDate(row.EndDate)
      }
    },
    handleCurrentChange(val) {
      this.pageIndex = val
      this.initHolidayList()
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.initHolidayList()
    }
  }
}
</script>

<style lang="scss">
.status-info{
  padding:5px 15px;
  font-size:13px;
  .el-form-item--mini.el-form-item{
    margin-bottom: 0px;
  }
  .el-form-item--small.el-form-item{
    margin-bottom: 0px;
  }
  .el-form-item__content{
    font-size: 13px;
  }
  .el-form-item__label{
    font-size: 13px;
    color: #303133;
    font-weight: bold;
  }
}
</style>
