<!-- =============================================================================
// 企微IT智能服务台 — 应急页坐席视图 (v0.5.4)
// =============================================================================
// 说明：BC/DR 应急场景下,显示坐席端 AI 助手面板
// 桌面端:全宽显示 AiAssistantPanel(AI推荐/快速回复/操作步骤/用户信息)
// 移动端:顶部"右栏"按钮,点击从右侧滑出 AI 助手面板
// ============================================================================= -->

<template>
  <div class="agent-preview">
    <!-- ====== 顶部条 ====== -->
    <div class="agent-preview__topbar">
      <div class="topbar-left">
        <span class="logo">🎧</span>
        <div class="title-block">
          <h1 class="title">坐席助手</h1>
          <p class="subtitle">IT 智能服务台 · 应急模式</p>
        </div>
      </div>
      <div class="topbar-right">
        <!-- 移动端:右栏按钮(打开抽屉) -->
        <el-button
          v-if="isMobile"
          type="primary"
          size="small"
          @click="drawerVisible = true"
        >
          <el-icon><Menu /></el-icon>
          <span>AI 助手</span>
        </el-button>
        <!-- 桌面端:userid 标签 -->
        <div v-else class="userid-tag">
          userid: {{ userid || 'anonymous' }}
        </div>
      </div>
    </div>

    <!-- ====== 桌面端:直接显示 AiAssistantPanel ====== -->
    <div v-if="!isMobile" class="agent-preview__content">
      <AiAssistantPanel />
    </div>

    <!-- ====== 移动端:抽屉(el-drawer 从右侧滑出) ====== -->
    <el-drawer
      v-if="isMobile"
      v-model="drawerVisible"
      direction="rtl"
      size="90%"
      :with-header="false"
    >
      <div class="agent-preview__drawer-header">
        <span class="drawer-title">🤖 AI 助手</span>
        <el-button
          type="text"
          size="small"
          @click="drawerVisible = false"
        >
          关闭
        </el-button>
      </div>
      <div class="agent-preview__drawer-body">
        <AiAssistantPanel />
      </div>
    </el-drawer>

    <!-- ====== 移动端:底部提示 ====== -->
    <div v-if="isMobile" class="agent-preview__mobile-hint">
      <p>💡 电脑端访问可获得完整体验(AI 助手常驻右侧)</p>
      <p>移动端请点上方"AI 助手"按钮打开</p>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'
import { useRoute } from 'vue-router'
import { ElMessage } from 'element-plus'
import { Menu } from '@element-plus/icons-vue'
import AiAssistantPanel from '@/components/assistant/AiAssistantPanel.vue'

const route = useRoute()
const drawerVisible = ref(false)
const userid = computed(() => (route.query.userid as string) || '')

const isMobile = computed(() => window.innerWidth < 500)

if (userid.value) {
  ElMessage({
    message: '坐席模式',
    type: 'success',
    duration: 1500,
  })
}
</script>

<style scoped>
.agent-preview {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: #f5f7fa;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', sans-serif;
}

/* ====== 顶部条 ====== */
.agent-preview__topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: white;
  border-bottom: 1px solid #e4e7ed;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  font-size: 28px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border-radius: 10px;
}

.title-block {
  display: flex;
  flex-direction: column;
}

.title {
  font-size: 16px;
  font-weight: 600;
  color: #303133;
  margin: 0;
}

.subtitle {
  font-size: 12px;
  color: #909399;
  margin: 0;
}

.userid-tag {
  font-size: 12px;
  color: #909399;
  padding: 4px 10px;
  background: #f5f7fa;
  border-radius: 4px;
}

/* ====== 桌面端内容区 ====== */
.agent-preview__content {
  flex: 1;
  overflow: hidden;
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  background: white;
}

/* ====== 抽屉 ====== */
.agent-preview__drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #e4e7ed;
  background: #fafafa;
}

.drawer-title {
  font-size: 15px;
  font-weight: 600;
  color: #303133;
}

.agent-preview__drawer-body {
  height: calc(100% - 45px);
  overflow-y: auto;
  background: white;
}

/* ====== 移动端提示 ====== */
.agent-preview__mobile-hint {
  padding: 12px 20px;
  background: #fdf6ec;
  color: #e6a23c;
  font-size: 12px;
  text-align: center;
  line-height: 1.6;
  border-top: 1px solid #faecd8;
}

.agent-preview__mobile-hint p {
  margin: 0;
}
</style>
