<script setup lang="ts">
import type { DiscussInfo, DiscussCommentItem } from '../types'
import { ChatLineRound } from '@element-plus/icons-vue'
import Avatar from '@/components/Avatar.vue'

interface Props {
  info: DiscussInfo
  list: DiscussCommentItem[]
}
defineProps<Props>()

defineEmits<{
  (e: 'update'): void
}>()
</script>
<template>
  <div class="discuss-item">
    <div class="discuss-box">
      <div class="discuss-box-user">
        <div class="discuss-box-user__avatar"><Avatar :src="info.created_operator_avatar" /></div>
        <div class="discuss-box-user__content">
          <h3>{{ info.student_id_name }}</h3>
          <p>{{ info.created_time }}</p>
        </div>
        <div class="button-comment">
          <el-icon><ChatLineRound></ChatLineRound></el-icon>{{ info.replies_num }}
        </div>
      </div>
      <div class="discuss-box-main">
        <h3>{{ info.title }}</h3>
        <div class="discuss-box-content" v-html="info.content"></div>
      </div>
    </div>
    <div class="discuss-comment" v-for="item in list" :key="item.id">
      <div class="discuss-comment__avatar">
        <Avatar :src="item.sso_id_avatar" />
      </div>
      <div class="discuss-comment-content">
        <span class="discuss-comment__username">{{ item.sso_id_name }}</span
        >：
        <span v-html="item.content"></span>
        <p class="discuss-comment-time">{{ item.created_time }}</p>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.discuss-box {
  padding-bottom: 20px;
  border-bottom: 1px solid #e6e6e6;
}
.discuss-box-user {
  display: flex;
  align-items: center;
  .button-comment {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333333;
    cursor: pointer;
    &.is-active {
      color: var(--main-color);
    }
  }
  .el-icon {
    font-size: 16px;
    margin-left: 10px;
    margin-right: 5px;
  }
}
.discuss-box-user__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
.discuss-box-user__content {
  flex: 1;
  margin-left: 10px;
  overflow: hidden;
  h3 {
    font-size: 16px;
    font-weight: 500;
    line-height: 20px;
    color: #333333;
  }
  p {
    font-size: 14px;
    font-weight: 400;
    line-height: 20px;
    color: #999999;
  }
}
.discuss-box-main {
  margin-left: 50px;
  h3 {
    padding: 16px 0;
    font-size: 16px;
    font-weight: 500;
    line-height: 20px;
    color: #333333;
  }
}
.discuss-box-content {
  font-size: 16px;
  font-weight: 400;
  line-height: 24px;
  color: #333333;
}

.discuss-comment {
  display: flex;
  margin-top: 20px;
}
.discuss-comment__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
.discuss-comment-content {
  flex: 1;
  margin-left: 10px;
  color: #333;
  overflow: hidden;
}
.discuss-comment__username {
  font-size: 16px;
  line-height: 20px;
  color: var(--main-color);
}
.discuss-comment-time {
  margin-top: 10px;
  font-size: 14px;
  line-height: 20px;
  color: #999999;
  text-align: right;
}
</style>
