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

interface Props {
  role: 'user' | 'assistant'
  messageItem: ConversationMessageItem
}

const { t } = useI18n()

defineProps<Props>()

const personalAppConfigStore = usePersonalAppConfigStore()

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
                ? t('common_module.dialogue_module.empty_message_content')
                : 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>
