<script lang="ts" setup>
import { computed, ref } from 'vue'
import ForwardRecord from '../ForwardRecord.vue'
import { ITalkRecordExtraForward, ITalkRecord } from '@/types/chat'

const props = defineProps<{
  extra: ITalkRecordExtraForward
  data: ITalkRecord
  maxWidth?: Boolean
}>()

const isShowRecord = ref(false)

const title = computed(() => {
  const uniqueNames = [...new Set(props.extra.records.map(v => v.nickname))];
  if (uniqueNames.length <= 2) {
    return uniqueNames.join('和');
  } else {
    return uniqueNames.slice(0, 2).join('和') + '等';
  }
  // return [...new Set(props.extra.records.map((v) => v.nickname))].join('和')
})
console.log(props.extra.records)
const onClick = () => {
  // isShowRecord.value = true
  uni.navigateTo({
    url: '/pages/forwardRecord/index?msgId=' + props.data.msg_id + '&created_at=' + props.data?.created_at
  })
}
</script>
<template>
  <section class="im-message-forward pointer" :class="{ left: data.float === 'left' }" @click="onClick">
    <div class="title">{{ extra.forward_name || title}}的会话记录</div>
    <div class="list" v-for="(record, index) in extra.records" :key="index">
      <p>
        <span>{{ record.nickname }}: </span>
        <span>{{ record.text }}</span>
      </p>
    </div>
    <div class="divider"></div>

    <div class="tips">
      <span>转发：聊天会话记录 ({{ extra.msg_ids.length }}条)</span>
    </div>

    <!-- <ForwardRecord v-if="isShowRecord" :msg-id="data.msg_id" @close="isShowRecord = false" /> -->
  </section>
</template>

<style lang="less" scoped>
.im-message-forward {
  width: 486rpx;
  min-height: 180rpx;
  max-height: 274rpx;
  border-radius: 0;
  background-color: #FFFFFF;
  padding: 22rpx 28rpx 22rpx 30rpx;
  &.left {
    background-color: #fff;
    border-radius: 0 16rpx 16rpx 16rpx;
  }
  &.right {
    background-color: #fff;
    border-radius: 16rpx 0 16rpx 16rpx;
  }

  .title {
    max-height: 88rpx;
    line-height: 44rpx;
    font-size: 32rpx;
    color: #1A1A1A;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    font-weight: 400;
    margin-bottom: 8rpx;
  }

  .list p {
    height: 34rpx;
    line-height: 34rpx;
    font-size: 24rpx;
    color: #B4B4B4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 10rpx;
  }

  .tips {
    height: 34rpx;
    line-height: 34rpx;
    color: #747474;
    font-size: 24rpx;
    margin-top: 10rpx;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.divider {
  height: 1rpx;
  background-color: #E7E7E7;
}
</style>
