<template>
  <div class="hopay-reviews">
    <div class="hotpay-review-item" v-for="review in data.reviewList" v-if="review.active" :class="{'single' : checkSingle}">
      <div class="hotpay-review-item-image">
        <img :src="review.image.file" :alt="review.name">
      </div>

      <div class="hotpay-review-item-body">
        <strong class="hotpay-review-item-title">{{ review.name }}</strong>

        <div class="hotpay-reviews-item-stars">
          <span v-for="star in 5">
            <svg-loader src="assets/images/icon-review-star-full.svg" v-if="star <= +review.stars" />
            <svg-loader src="assets/images/icon-review-star-empty.svg" v-else />
          </span>
        </div>

        <p class="hotpay-review-item-content">"{{ review.text }}"</p>
      </div>
    </div>
  </div>
</template>

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

  .hopay-reviews {
    display: flex;
    justify-content: center;
  }

  .hotpay-review-item {
    margin-bottom: 24px;
    padding: 10px 24px 15px;
    min-width: 300px;
    width: 33.3%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: 1px solid rgba($color-light-gray, .7);
    border-radius: 7px;
    text-align: center;

    &.single {
      border: none;
      display: flex;
      flex-direction: row;
      width: auto;
      max-width: 600px;
      min-height: 170px;

      .hotpay-review-item-image {
        margin-right: 40px;
      }

      .hotpay-review-item-body {
        text-align: left;
      }

      .hotpay-review-item-title {
        margin-top: 0;
      }
    }

    & + .hotpay-review-item {
      margin-left: 15px;
    }
  }

  .hotpay-review-item-image {
    overflow: hidden;
    min-width: 110px;
    height: 110px;
    align-self: center;
  }

  .hotpay-review-item-body {
    overflow: hidden;
  }

  img {
    width: 110px;
    height: 110px;
    border-radius: 100%;
  }

  .hotpay-review-item-title {
    margin: 10px 0 5px;
    color: $color-blue;
    font-size: 20px;
    font-weight: 600;
    line-height: 1.3em;
    display: block;
  }

  .hotpay-review-item-content {
    margin: 5px 0 0 0;
    color: $color-light-gray;
    font-size: 18px;
    font-style: italic;
    line-height: 1.2em;
  }

  .hotpay-reviews-item-stars {
    display: inline-flex;

    span {
      margin-right: 4px;
    }
  }
</style>

<script>
  export default {
    name: 'hotpay-reviews',
    props: {
      data: {
        type: Object,
        default: () => ({
          reviewList: [],
          activeItems: []
        })
      }
    },
    data: () => ({
      single: false,
      activeList: []
    }),
    computed: {
      checkSingle () {
        return this.activeList.length === 1
      }
    },
    methods: {
      createActiveList () {
        const { reviewList } = this.data

        this.activeList = reviewList.filter((current) => {
          return current.active
        })
      }
    },
    watch: {
      data: {
        deep: true,
        handler () {
          this.createActiveList()
        }
      }
    },
    mounted () {
      this.createActiveList()
    }
  }
</script>
