<template>
  <div class="review-wrapper">
    <div
      style="display: flex; align-items: center; justify-content: space-between"
    >
      <div style="display: flex; align-items: center">
        <star-rating v-bind:rating="rating" v-bind:starForReview="true" />
        <div class="userId-text">
          {{ encrypteUserId(userId) }}
        </div>
      </div>
      <div style="font-size: 12px; color: var(--COLOR_GREY_6)">
        {{ createdAt }}
      </div>
    </div>
    <div class="option-text">
      {{ option }}
    </div>
    <p class="desc-text">
      {{ show200Letters(description) }}
    </p>
    <div class="review-footer" v-on:click="onClickHelpfulButton()">
      <span style="font-size: 12px; color: var(--COLOR_GREY_5_5)"
        >이 리뷰가 도움이 되었나요?</span
      >
      <div class="review-help-button" v-bind:class="{ checked: amIchecked }">
        도움이 돼요
        <span
          v-if="countOfHelp > 0"
          style="font-size: 13px; font-weight: bold; color: var(--COLOR_BLUE_5)"
          >{{ countOfHelp }}</span
        >
      </div>
    </div>
  </div>
</template>

<script>
import StarRating from "./starRating.vue";

export default {
  name: "singleReview",
  components: {
    "star-rating": StarRating,
  },
  props: {
    rating: String,
    userId: String,
    createdAt: String,
    option: String,
    description: String,
    countOfHelp: Number,
    amIchecked: Boolean,
  },
  methods: {
    encrypteUserId() {
      const lengthOfId = this.userId.length;
      if (lengthOfId > 4) {
        const showId = this.userId.substring(0, 4);
        const hideId = "*".repeat(lengthOfId - 4);
        return showId + hideId;
      }
      const showId = this.userId.substring(0, 1);
      const hideId = "*".repeat(lengthOfId - 1);
      return showId + hideId;
    },
    show200Letters() {
      const lengthOfText = this.description.length;
      if (lengthOfText > 200) {
        const showText = this.description.substring(0, 200);
        return showText + "...";
      }
      return this.description;
    },
    onClickHelpfulButton() {
      console.log("click!");
    },
  },
};
</script>

<style scopped>
.review-wrapper {
  max-width: 800px;
  margin: 0 auto;
  margin-top: 16px;
}
.userId-text {
  border-left: 1px solid var(--COLOR_GREY_3);
  padding-left: 6px;
  margin-left: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--COLOR_TEXT_PRIMARY);
}
.option-text {
  font-size: 13px;
  color: var(--COLOR_GREY_5_5);
  margin: 12px 0;
  line-height: 19px;
}
.desc-text {
  font-size: 13px;
  color: var(--COLOR_TEXT_PRIMARY);
  line-height: 19px;
}
.review-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 24px 0;
}
.review-help-button {
  font-size: 12px;
  font-weight: 500;
  color: var(--COLOR_GREY_6);
  padding: 6px 12px;
  border: 1px solid var(--COLOR_GREY_3);
  border-radius: 16px;
}
.review-help-button.checked {
  border: 1px solid var(--COLOR_BLUE_3);
  font-weight: bold;
}
</style>
