<!-- =============================================================================
// 企微IT智能服务台 — 应急页员工视图 (v0.5.4)
// =============================================================================
// 说明：BC/DR 应急场景下,显示 H5 用户端右栏内容
// 桌面端:全宽显示 RightPanel(三段式:AI推荐/常用资源/趣味问答)
// 移动端:顶部"菜单"按钮,点击从顶部滑出右栏内容(抽屉式)
// ============================================================================= -->

<template>
  <div class="h5-preview">
    <!-- ====== 顶部条(移动端 + 桌面端都有) ====== -->
    <div class="h5-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>
      <!-- 移动端:菜单按钮(打开抽屉) -->
      <button
        v-if="isMobile"
        class="topbar-menu-btn"
        @click="drawerVisible = true"
      >
        <van-icon name="apps-o" size="22" />
        <span>右栏</span>
      </button>
      <!-- 桌面端:显示 userid(供验证) -->
      <div v-else class="userid-tag">
        userid: {{ userid || 'anonymous' }}
      </div>
    </div>

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

    <!-- ====== 移动端:抽屉(Vant Popup 从顶部弹出) ====== -->
    <van-popup
      v-if="isMobile"
      v-model:show="drawerVisible"
      position="top"
      :style="{ height: '85%' }"
      :close-on-click-overlay="true"
      closeable
      safe-area-inset-top
    >
      <div class="h5-preview__drawer-header">
        <span class="drawer-title">📋 右栏内容</span>
        <van-icon
          name="cross"
          size="20"
          class="drawer-close"
          @click="drawerVisible = false"
        />
      </div>
      <div class="h5-preview__drawer-body">
        <RightPanel />
      </div>
    </van-popup>

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

<script setup lang="ts">
import { ref, computed } from 'vue'
import { useRoute } from 'vue-router'
import { showToast } from 'vant'
import RightPanel from '@/components/assistant/RightPanel.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) {
  showToast({ message: '员工模式', duration: 1500 })
}
</script>

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

/* ====== 顶部条 ====== */
.h5-preview__topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: white;
  border-bottom: 1px solid #ebedf0;
  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, #e3f2fd 0%, #bbdefb 100%);
  border-radius: 10px;
}

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

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

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

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

/* 菜单按钮(移动端) */
.topbar-menu-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: linear-gradient(135deg, #1989fa 0%, #1c64f2 100%);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
}

.topbar-menu-btn:active {
  opacity: 0.8;
}

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

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

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

.drawer-close {
  color: #969799;
  cursor: pointer;
}

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

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

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