import { ref } from 'vue'
import type { ChatMessage } from './types'

export function useSkillChat() {
  // AI 对话面板
  const isChatOpen = ref(false)

  // 对话相关
  const chatInput = ref('')
  const chatMessages = ref<ChatMessage[]>([])

  const toggleChat = () => {
    isChatOpen.value = !isChatOpen.value
  }

  const sendMessage = () => {
    if (!chatInput.value.trim()) return

    chatMessages.value.push({
      id: Date.now(),
      text: chatInput.value
    })

    const userInput = chatInput.value
    chatInput.value = ''

    // 模拟 AI 回复
    setTimeout(() => {
      chatMessages.value.push({
        id: Date.now(),
        text: `I've updated the configuration based on your request: "${userInput}". The changes have been applied to your skill settings.`
      })
    }, 1000)
  }

  return {
    // State
    isChatOpen,
    chatInput,
    chatMessages,

    // Methods
    toggleChat,
    sendMessage,
  }
}
