<script setup lang="ts">
import CustomLoading from './custom-loading.vue'
import { usePersonalAppConfigStore } from '@/store/modules/personal-app-config'
import MarkdownRender from '@/components/markdown-render/markdown-render.vue'

const personalAppConfigStore = usePersonalAppConfigStore()
interface Props {
  role: 'user' | 'assistant'
  messageItem: ConversationMessageItem
}

defineProps<Props>()

const useAvatar = 'https://mkp-dev.oss-cn-shenzhen.aliyuncs.com/data/upload/20240827/1724728478476.png'
const assistantAvatar = personalAppConfigStore.baseInfo.agentAvatar
</script>

<template>
  <div class="mb-5 flex last:mb-0">
    <NImage
      :src="role === 'user' ? useAvatar : assistantAvatar"
      preview-disabled
      :width="32"
      :height="32"
      class="mr-2 mt-1.5 h-8 w-8 rounded-full"
    />

    <div
      class="min-w-[80px] max-w-[calc(100%-32px-12px)] flex-wrap rounded-xl border border-[#e8e9eb] px-4 py-[11px]"
      :class="role === 'user' ? 'bg-[#4b87ff] text-white' : 'bg-white text-[#333]'"
    >
      <div v-if="messageItem.isTextContentLoading" class="py-1.5 pl-4">
        <CustomLoading />
      </div>

      <div v-else>
        <p class="break-all">
          <MarkdownRender
            :raw-text-content="messageItem.isEmptyContent ? '[空内容]' : messageItem.textContent"
            :color="role === 'user' ? '#fff' : '#192338'"
          />
        </p>

        <div v-show="role === 'assistant' && messageItem.isAnswerResponseLoading" class="mb-[5px] mt-4 px-4">
          <CustomLoading />
        </div>
      </div>
    </div>
  </div>
</template>
