<script lang="ts" setup>
import type { LocalMessage } from "~/types";

defineProps({
  message: {
    type: Object as PropType<LocalMessage>,
    default: null,
  },
  name: {
    type: String,
    default: "AI 智慧校园",
  },
  icon: {
    type: String,
    default: "tabler:robot-face",
  },
});
</script>

<template>
  <div v-if="message.role === 'user'" class="flex flex-col items-end gap-2">
    <div
      class="rounded-2xl rounded-br-none bg-primary-400 px-3 py-2 text-sm w-fit max-w-8/12 break-all text-justify text-white font-medium dark:bg-primary-500"
    >
      {{ message.message }}
    </div>
  </div>
  <div v-else-if="message.role === 'bot'" class="flex flex-col gap-2">
    <div class="flex gap-1.5 items-center">
      <div
        class="w-7 h-7 rounded-lg border border-neutral-200 bg-white shadow-sm flex justify-center items-center dark:bg-neutral-700 dark:border-neutral-600"
      >
        <UIcon :name="icon" />
      </div>
      <span class="text-sm font-medium">{{ name }}</span>
    </div>
    <div
      class="rounded-lg bg-white/50 p-2 text-sm dark:bg-neutral-800/50 break-all text-justify"
    >
      <div v-if="message.message" class="prose prose-sm">
        {{ message.message }}
      </div>
      <span v-else class="flex items-center gap-1.5">
        <UIcon name="svg-spinners:3-dots-scale" class="text-lg -mt-0.5" />
        <p class="text-xs">思考中</p>
      </span>
    </div>
  </div>
</template>

<style scoped></style>
