<template>
  <div class="demo-container">
    <h1>浮动聊天按钮组件演示</h1>
    
    <div class="demo-section">
      <h2>基本使用</h2>
      <p>点击"跟我聊聊"按钮，会弹出功能选择面板，包含AI助手和反馈中心两个选项。</p>
      
      <!-- 浮动聊天按钮 -->
      <HelpChatButton
        :themeColor="'rgb(234 102 155)'"
        :position="{ bottom: '20px', right: '20px' }"
        :draggable="true"
        :aiChatConfig="{ pollingInterval: 500, botCode: 'WEB_QA_RHINO' }"
        :feedbackConfig="{ systemId: 'xxxxxxx' }"
        :userId="'00000'"
        :userName="'cs@fintopia.tech'"
        @ai-chat-open="handleAiChatOpen"
        @feedback-open="handleFeedbackOpen"
      />
    </div>

    <div class="demo-section">
      <h2>功能说明</h2>
      <ul>
        <li><strong>拖拽功能：</strong>按钮可以拖拽到页面任意位置</li>
        <li><strong>功能面板：</strong>点击按钮弹出包含AI助手和反馈中心的选择面板</li>
        <li><strong>AI助手：</strong>点击后打开AI聊天功能，使用插槽方式集成现有组件</li>
        <li><strong>反馈中心：</strong>点击后打开反馈面板，支持自定义第三方组件</li>
        <li><strong>响应式设计：</strong>面板会根据按钮位置自动调整显示位置</li>
      </ul>
    </div>

    <div class="demo-section">
      <h2>事件日志</h2>
      <div class="event-log">
        <div v-for="(event, index) in eventLog" :key="index" class="event-item">
          {{ event }}
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { HelpChatButton } from '../components/help-chat-button'

// 事件日志
const eventLog = ref<string[]>([])

// 添加事件日志
const addEventLog = (message: string) => {
  const timestamp = new Date().toLocaleTimeString()
  eventLog.value.unshift(`[${timestamp}] ${message}`)
  if (eventLog.value.length > 10) {
    eventLog.value.pop()
  }
}

// AI聊天打开事件
const handleAiChatOpen = () => {
  addEventLog('AI聊天面板已打开')
}

// 反馈中心打开事件
const handleFeedbackOpen = () => {
  addEventLog('反馈中心面板已打开')
}
</script>

<style scoped>
.demo-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.demo-section {
  margin-bottom: 40px;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
}

.demo-section h1 {
  color: #333;
  margin-bottom: 20px;
}

.demo-section h2 {
  color: #555;
  margin-bottom: 15px;
  font-size: 20px;
}

.demo-section p {
  color: #666;
  line-height: 1.6;
  margin-bottom: 15px;
}

.demo-section ul {
  color: #666;
  line-height: 1.8;
  padding-left: 20px;
}

.demo-section li {
  margin-bottom: 8px;
}


/* 事件日志样式 */
.event-log {
  max-height: 300px;
  overflow-y: auto;
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 15px;
}

.event-item {
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 13px;
  color: #666;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
}

.event-item:last-child {
  border-bottom: none;
}

.event-item:first-child {
  color: #333;
  font-weight: 500;
}
</style>
