<script setup lang="ts">
import type { type_dyaw_xlfw_zxhd_log } from '~/types';
import { formatTimestamp, formatTimeToShow } from '~/utils/time';
const props = defineProps<{
  left: boolean,
  virtualName?: string,
  w: number,
  d: type_dyaw_xlfw_zxhd_log
}>()


const id2name = {
  [props.d.dxzl_stu_user_id]: props.virtualName ?? props.d.dxzl_stu_user_realname,
  [props.d.dxzl_tea_user_id]: props.d.dxzl_tea_user_realname,
}


const showMsg = $computed(() => decodeURIComponent(props.d.dxzl_last_msg_content!))
</script>

<template>
  <div class="w-full" :class="left ? 'left' : 'right'">
    <div class="flex items-end r_flex-row-reverse gap-4">
      <div>{{ id2name[d.create_user_id] }}</div>
      <div class="text-sm text-hex-AFB2B6">{{ formatTimeToShow(parseInt(props.d.create_dateline) * 1000) }}</div>
    </div>
    <div class="flex mt-2 r_flex-row-reverse">
      <div class=" py-10px px-14px rounded-3xl min-h-44px bg-white text_wrapper min-w-50px" :style="`max-width:${props.w}px`"
        v-html="showMsg">
      </div>
    </div>

  </div>
</template>

<style scoped lang="scss">
.text_wrapper :deep(p) {
  margin: 0;
  padding: 0;
  word-wrap: break-word;

  img{
    display: inline-block;
    vertical-align: bottom;
    margin: 0 2px;
  }
}


.left {
  .text_wrapper {
    border-radius: 2px 24px 24px 24px;
  }
}

.right {
  .r_flex-row-reverse {
    flex-direction: row-reverse;
  }

  .text_wrapper {
    background-color: #397FF6;
    color: white;
    border-radius: 24px 2px 24px 24px;
  }
}
</style>
