import ChatMessage from '@/components/chatroom/ChatMessage.vue'

interface UserMessage {
  role: 'user'
  message: string
  mode: 'continue' | 'expand'
}

interface AiiMessage {
  role: 'assistant'
  message: string
}

type Message = UserMessage | AiiMessage
type MessageList = Message[]

export function createChatTableMessages(
  content: string,
  onMessageEdit: (oldMessage: string, newMessage: string, change: 'aii' | 'user') => void,
  onMessageDelete: (message: string, change: 'aii' | 'user') => void,
) {
  if (!content) return
  const content_list: MessageList = JSON.parse(content)
  return (
    <>
      {content_list.map((msg: Message) => {
        return (
          <ChatMessage
            msg={msg.message}
            role={msg.role === 'assistant' ? 'aii' : 'user'}
            onMessageEdit={onMessageEdit}
            onMessageDelete={onMessageDelete}
          />
        )
      })}
    </>
  )
}
