<template>
  <div class="card-container">
    <div class="card-content" v-loading="loading">
      <el-form
        label-position="left"
        label-width="140px"
        style="width: 100%;">
        <el-row :gutter="20">
          <el-col :xs="24" :md="12">
            <div class="section-title">Feedback</div>
            <el-row :gutter="20">
              <el-col :xs="24">
                <el-form-item
                  label="Type of Feedback:">
                  <el-input
                    class="add-text"
                    v-model="feedbackInfo.typeOfFeedback"
                    readonly/>
                </el-form-item>
              </el-col>
              <el-col :xs="24">
                <el-form-item
                  label="Feedback:">
                  <el-input
                    class="add-text"
                    :autosize="autosize"
                    v-model="feedbackInfo.feedback"
                    type="textarea"
                    readonly/>
                </el-form-item>
              </el-col>
              <el-col :xs="24">
                <el-form-item
                  label="Feedback Status:">
                  <el-input
                    class="add-text"
                    :value='feedbackInfo.readStatus ? "Readed" : "Unread"'
                    readonly/>
                </el-form-item>
              </el-col>
              <el-col :xs="24">
                <el-form-item
                  label="Feedback By:">
                  <el-input
                    class="add-text"
                    v-model="feedbackInfo.nickName"
                    readonly/>
                </el-form-item>
              </el-col>
              <el-col :xs="24">
                <el-form-item
                  label="Feedback Time:">
                  <el-input
                    class="add-text"
                    v-model="feedbackInfo.feedbackTime"
                    readonly/>
                </el-form-item>
              </el-col>
              <el-col :xs="24" v-if="feedbackInfo.chargeBoxId">
                <el-form-item
                  label="Charging Station:">
                  <el-input
                    class="add-text"
                    v-model="feedbackInfo.chargeBoxId"
                    readonly/>
                </el-form-item>
              </el-col>
              <el-col :xs="24" v-if="feedbackInfo.connectorId">
                <el-form-item
                  label="Connector:">
                  <el-input
                    class="add-text"
                    v-model="feedbackInfo.connectorId"
                    readonly/>
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
          <el-col :xs="24" :md="12">
            <div class="section-title">Photos</div>
            <div class="feedback-photo">
              <img
                class="feedback-img"
                :src="baseURL + feedbackInfo.feedbackImgOne"
                v-if="feedbackInfo.feedbackImgOne"/>
              <img
                class="feedback-img"
                :src="baseURL + feedbackInfo.feedbackImgTwo"
                v-if="feedbackInfo.feedbackImgTwo"/>
              <img
                class="feedback-img"
                :src="baseURL + feedbackInfo.feedbackImgThree"
                v-if="feedbackInfo.feedbackImgThree"/>
            </div>
          </el-col>
        </el-row>
        <div class="hr-full"/>
        <div class="buttons">
          <el-button
            type="primary"
            class="cancel-button"
            @click="handleBackClick">
            Back
          </el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
  //import { mapState } from 'vuex'
  import {baseURL} from '../../http/http'
  import feedback from '../../http/api/feedback'
  export default {
    data() {
      return {
        baseURL: baseURL,
        loading: false,
        autosize: {
          minRows: 3,
          maxRows: 10,
        },
        feedbackInfo: {}
      }
    },
    created() {
      if (this.$route.params.id) {
        this.readedFeedback()
      }
    },
    methods: {
      readedFeedback() {
        this.loading = true;
        feedback.readFeedback(this.$route.params.id).then(res => {
          if (res.data) {
            this.feedbackInfo = res.data
          }
        }).catch(err => {
          this.$message({
            message: err,
            type: 'error'
          })
        }).finally(() => {
          this.loading = false;
        })
      },      
      handleBackClick() {
        this.$nextTick(() => {
          this.$router.replace({
            path: "/support-management/feedbacks"
          })
        })
      }
    }
  }
</script>

<style scoped="scoped" lang='scss'>
  @import '../../styles/variables.scss';

  .card-container {
    width: 100%;
    padding: 20px 60px;
    min-height: $mainAppMinHeight;
    background-color: #F0F5FC;
  }
  .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: 400px;
  }
  .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;
    flex-wrap: wrap;
    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;
  }
  .feedback-photo {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding-bottom: 20px;
  }
  .feedback-img {
    width: 180px;
    margin-right: 20px;
  }
  @media screen and (max-width: 500px) {
    .card-container {
      padding: 0px;
    }
    .card-content {
      padding: 15px 40px;
    }
    .feedback-photo {
      justify-content: center;
    }
    .feedback-img {
      width: 80vw;
      margin-top: 10px;
      margin-right: 0;
    }
  }
</style>
