<template>
  <div class="card-container">
    <div class="card-content">
      <el-form
        :model="creditLimitInfo"
        v-loading="loading"
        ref="creditLimitInfo"
        label-position="right"
        label-width="180px">
        <div class="section-title">Monthly Credit Limit:</div>
        <el-row :gutter="20">
          <el-col :xs="24" :md="12">
            <el-form-item label="Fleet Company:">
              <el-input
                class="add-text"
                v-model="creditLimit.fleetCompany"
                readonly/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :md="12">
            <el-form-item label="Status:">
              <el-input
                class="add-text"
                v-model="creditLimit.creditLimitStatus"
                readonly/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :xs="24" :md="12">
            <el-form-item label="Monthly Credit Limit:">
              <span class="item-unit">(S$)</span>
              <el-input
                class="add-text"
                v-model="creditLimitInfo.creditLimitAmount"
                readonly/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :md="12">
            <el-form-item label="Effective Start Date:">
              <el-input
                class="add-text"
                v-model="creditLimitInfo.effectiveStartDate"
                readonly/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :xs="24" :md="12">
            <el-form-item label="Used Credit Limit:">
              <span class="item-unit">(S$)</span>
              <el-input
                class="add-text"
                v-model="creditLimitInfo.usedCreditLimitAmount"
                readonly/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :md="12">
            <el-form-item label="Effective End Date:">
              <el-input
                class="add-text"
                v-model="creditLimitInfo.effectiveEndDate"
                readonly/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :xs="24" :md="12">
            <el-form-item
              label="Remaining Credit Limit:"
              prop="chargeBoxId">
              <span class="item-unit">(S$)</span>
              <el-input
                class="add-text"
                v-model="creditLimitInfo.creditLimitRemainingAmount"
                readonly/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :md="12">
            <el-form-item
              label="Deposit Received:"
              prop="depositReceivedAmount">
              <span class="item-unit">(S$)</span>
              <el-input
                class="add-text"
                v-model="creditLimitInfo.depositReceivedAmount"
                readonly/>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="hr-full"/>
        <div class="buttons">
          <el-button
            type="primary"
            class="cancel-button"
            @click="handleClickCancleButton">
            Back
          </el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
  import { mapState } from 'vuex'
  import limit from '../../http/api/limit.js'
  import { fetchFleetCompanyPages } from '../../http/api/fleetCompany';
  export default {
    data() {
      return {
        loading: false,
        creditLimitInfo: {
          creditLimitId: 0,
          fleetCompanyId: '',
          creditLimitAmount: '',
          depositReceivedAmount: '',
          effectiveStartDate: "",
          effectiveEndDate: "",
          creditLimitStatus: ""
        }
      }
    },
    computed: {
      ...mapState('provider', ['creditLimit'])
    },
    created() {
      this.loading = true;
      this.getLimitInfo();
    },
    methods: {
      getLimitInfo() {
        var id = this.creditLimit.creditLimitId;
        if (!id) id = this.$route.params.id;
        limit.viewCreditLimit(id).then(res => {
          this.loading = false;
          if (res.data) {
            this.creditLimitInfo = res.data
          }
        }).catch(err => {
          this.loading = false;
          this.$message({
            message: err,
            type: 'error'
          })
        });
      },
      handleClickCancleButton() {
        this.$router.go(-1)
      }
    }
  }
</script>

<style scoped="scoped" lang='scss'>
  @import '../../styles/variables.scss';
  
  .card-container {
    width: 100%;
    padding: 20px 60px;
    min-height: $mainAppMinHeight;
    background-color: #F0F5FC;
  }
  .card-content {
    padding: 15px 80px;
    border-radius: 6px;
    background-color: white;
  }
  .section-title {
    color: #333;
    margin-top: 20px;
    margin-bottom: 30px;
    font-size: 16px;
    user-select: none;
    line-height: 24px;
    font-weight: 500;
    font-family: sans-serif;
    text-transform: uppercase;
  }
  .add-text {
    width: 100%;
    max-width: 300px;
  }
  .add-text ::v-deep .el-textarea__inner {
    font-family: sans-serif;
  }
  .hr {
    height: 2px;
    margin: 10px -40px;
    background-color: #F0F5FC;
  }
  .hr-full {
    height: 2px;
    margin: 20px -80px;
    background-color: #F0F5FC;
  }
  .rate-list-view {
    display: flex;
    align-items: center;
  }
  .rate-text {
    max-width: 150px;
    padding-right: 14px;
  }
  .list-item-icon {
    width: 30px;
    height: 30px;
    cursor: pointer;
    margin: 0 10px 22px;
  }
  .buttons {
    padding-top: 15px;
    padding-bottom: 30px;
  }
  @media screen and (max-width: 500px) {
    .card-container {
      padding: 0px;
    }
    .card-content {
      padding: 15px 30px;
    }
  }
  .item-unit {
    top: 12px;
    left: -40px;
    font-size: 12px;
    user-select: none;
    position: absolute;
  }
</style>
