<template>
  <div class="card-container">
    <el-form
      label-position="right"
      label-width="140px"
      style="width: 100%;"
      v-loading="loading">
      <div class="flexr">
        <div class="flex1 card-content">
          <div class="section-title">Feedback</div>
          <el-form-item
            label="Type of Feedback:">
            <el-input
              class="add-text"
              v-model="feedbackInfo.typeOfFeedback"
              readonly/>
          </el-form-item>
          <el-form-item
            label="Feedback:">
            <el-input
              class="add-text"
              :autosize="autosize"
              v-model="feedbackInfo.feedback"
              type="textarea"
              readonly/>
          </el-form-item>
          <el-form-item
            label="Feedback Status:">
            <el-input
              class="add-text"
              :value='feedbackInfo.readStatus ? "Read" : "Unread"'
              readonly/>
          </el-form-item>
          <el-form-item
            label="Feedback By:">
            <el-input
              class="add-text"
              v-model="feedbackInfo.nickName"
              readonly/>
          </el-form-item>
          <el-form-item
            label="Feedback Time:">
            <el-input
              class="add-text"
              v-model="feedbackInfo.feedbackTime"
              readonly/>
          </el-form-item>
          <el-form-item
            label="Charging Station:"
            v-if="feedbackInfo.chargeBoxId">
            <el-input
              class="add-text"
              v-model="feedbackInfo.chargeBoxId"
              readonly/>
          </el-form-item>
          <el-form-item
            label="Connector:"
            v-if="feedbackInfo.connectorId">
            <el-input
              class="add-text"
              v-model="feedbackInfo.connectorId"
              readonly/>
          </el-form-item>
        </div>
        <div class="flex1 card-content">
          <div class="section-title">Photos</div>
          <div class="feedback-photo">
            <el-image
              class="feedback-img"
              :src="$imageSrc(feedbackInfo.feedbackImgOne)"
              :previewSrcList="[$imageSrc(feedbackInfo.feedbackImgOne)]"
              v-if="feedbackInfo.feedbackImgOne"/>
            <el-image
              class="feedback-img"
              :src="$imageSrc(feedbackInfo.feedbackImgTwo)"
              :previewSrcList="[$imageSrc(feedbackInfo.feedbackImgTwo)]"
              v-if="feedbackInfo.feedbackImgTwo"/>
            <el-image
              class="feedback-img"
              :src="$imageSrc(feedbackInfo.feedbackImgThree)"
              :previewSrcList="[$imageSrc(feedbackInfo.feedbackImgThree)]"
              v-if="feedbackInfo.feedbackImgThree"/>
          </div>
        </div>
      </div>
      <div class="card-content flexcr">
        <div class="buttons">
          <el-button
            type="primary"
            class="cancel-button"
            @click="handleBackClick">
            Back
          </el-button>
        </div>
      </div>
    </el-form>
  </div>
</template>

<script>
  //import { mapState } from 'vuex'
  import feedback from '../../http/api/feedback'
  export default {
    data() {
      return {
        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-content {
    margin: 0 8px 16px;
    padding: 15px 80px;
    border-radius: 6px;
    background-color: white;
  }
  .section-title {
    color: #333;
    margin-top: 20px;
    margin-bottom: 30px;
    font-size: 15px;
    user-select: none;
    line-height: 24px;
    font-weight: bold;
    font-family: sans-serif;
    text-transform: uppercase;
  }
  .add-text {
    width: 100%;
    min-width: 100px;
    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;
    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: 15px;
  }
  .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>
