<template>
  <div class="message-card" :class="classes">
    <div class="message-card-content">
      <div class="message-arrow"></div>
      <slot :data="data.payload">
        <div class="message-card-text" v-if="data.type === 0">{{data.payload.text}}</div>
        <course-tag-message
          :courseId="courseId"
          :isTest="isTest"
          :data="data.payload"
          v-on="$listeners"
          v-if="data.type === 1"
        ></course-tag-message>
        <search-tag-message
          :courseId="courseId"
          :isTest="isTest"
          :data="data.payload"
          v-on="$listeners"
          v-if="data.type === 2"
        ></search-tag-message>
        <tag-message
          :courseId="courseId"
          :data="data.payload"
          v-on="$listeners"
          v-if="data.type === 3"
        ></tag-message>
      </slot>
    </div>
  </div>
</template>
<script>
import CourseTagMessage from './courseTagMessage.vue'
import SearchTagMessage from './searchTagMessage.vue'
import TagMessage from './tagMessage.vue'

export default {
  name: 'MessageCard',
  props: {
    courseId: { type: String },
    isTest: { type: Boolean, default: false },
    data: { type: Object }
  },
  components: { CourseTagMessage, SearchTagMessage, TagMessage },
  computed: {
    isMyPublish() {
      return this.data.from === 'user'
    },
    classes() {
      return {
        'is-my': this.isMyPublish,
        'is-system': !this.isMyPublish
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.message-card {
  clear: both;
  margin-bottom: 20px;
}
.message-card-text {
  display: inline-block;
  padding: 10px;
  background-color: #fff;
  border-radius: 6px;
}
.is-my {
  .message-arrow {
    position: absolute;
    right: -5px;
    top: 16px;
    width: 0;
    height: 0;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-left: 5px solid #67a8ff;
  }
  .message-card-content {
    text-align: right;
  }
  .message-card-text {
    text-align: left;
    color: #fff;
    background-color: #67a8ff;
  }
}
.message-card-content {
  position: relative;
}
.is-system {
  .message-arrow {
    position: absolute;
    left: -5px;
    top: 16px;
    width: 0;
    height: 0;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-right: 5px solid #fff;
  }
}
</style>
