<template>
  <!-- AI实验室 -->
  <div class="home-container">
    <!-- 左侧折叠面板 -->
    <div class="left-group">
      <el-row class="tac">
        <el-col :span="12">
          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            @open="handleOpen"
            @close="handleClose"
          >
            <el-menu-item @click="handleMenuItemClick(item)" v-for="(item, index) in groupList" :key="index">
              <el-icon><component :is="item.icon" /></el-icon>
              <span>{{ item.title }}</span>
            </el-menu-item>
          </el-menu>
        </el-col>
      </el-row>
    </div>
    <!-- 右侧数字人 -->
    <div class="number-people">
      <div class="title-box">
        <div class="box-icon" @click="goBack">
          <el-icon class="left-icon"><ArrowLeftBold /></el-icon>
          AI实验室 | {{ groupList[2].title }}
        </div>
      </div>

      <div class="content-box">
        <!-- 动态渲染数字人 -->
        <div
          v-for="(person, index) in peopleList"
          :key="index"
          @click="navigateToAIQuestions(person)"
          class="small-box"
        >
          <div class="people-box">
            <img :src="person.image" alt="{{ person.name }}" />
          </div>
          <div class="people-title">{{ person.name }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import {
  Document,
  Menu as IconMenu,
  Setting,
  ArrowLeftBold
} from '@element-plus/icons-vue'
const router = useRouter()

// 返回上一页
const goBack = () => {
  router.go(-1)
}
// 引入
import NumberPeople01 from '@/assets/images/number-people01.png'
import NumberPeople02 from '@/assets/images/number-people02.png'
import NumberPeople03 from '@/assets/images/number-people03.png'
import NumberPeople04 from '@/assets/images/number-people04.png'
import NumberPeople05 from '@/assets/images/number-people05.png'

// 渲染数字人老师及图片
const peopleList = ref([
  { id: 10, name: '小智', image: NumberPeople01 },
  { id: 21, name: '鲁迅', image: NumberPeople01 },
  { id: 22, name: '门捷列夫', image: NumberPeople02 },
  { id: 19, name: '牛顿', image: NumberPeople03 },
  { id: 23, name: '特斯拉', image: NumberPeople04 },
  { id: 18, name: '李白', image: NumberPeople05 }
])

// 跳转页面携带名字和人物形象
const navigateToAIQuestions = person => {
  router.push({
    // 跳转问答页面
    path: '/ai-questions',
    query: { id: person.id, name: person.name, image: person.image }
  })
  // console.log(person.id)
}

// 处理菜单项点击事件
const handleMenuItemClick = (item) => {
  if (item.title === '智能绘图') {
    router.push('/ai-painting')
  }
}

// 渲染侧边栏
const groupList = ref([
  {
    icon: IconMenu,
    title: '智能问答'
  },
  {
    icon: Document,
    title: '智能绘图',
  },
  {
    icon: Setting,
    title: '数字人老师'
  }
])
</script>

<style scoped lang="scss">
@use 'sass:math';
// 定义rpx转换函数
@function rpx($px) {
  @return math.div($px, 750) * 100vw;
}
.home-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: row;
  gap: rpx(0);
}

// 侧边栏
.left-group {
  width: rpx(150);
  height: 100%;
  background: linear-gradient(to bottom, #001169, #b4a8e1);
}
.mb-2 {
  color: black;
  margin-top: rpx(1);
}
.tac ::v-deep(.el-menu) {
  background-color: transparent;
  border: none;
  width: 100%;
  margin-top: rpx(30);
  margin-left: rpx(10);
}
.el-menu-item {
  width: rpx(130);
  height: rpx(25);
  margin-bottom: rpx(5);
  border-radius: rpx(6);
}
.el-menu-item .el-icon svg {
  font-size: rpx(15);
  color: white;
}
.el-menu-item span {
  color: white;
  font-size: rpx(8);
  padding-left: rpx(5);
}
.el-menu ::v-deep(.el-menu-item:hover),
.el-menu ::v-deep(.el-menu-item:focus),
.el-menu ::v-deep(.el-menu-item:active) {
  background: linear-gradient(
    to bottom,
    #fee78a,
    #ffce1b
  ); /* 设置悬停、聚焦、点击状态下的背景色 */
}

// 右侧数字人内容
.number-people {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column; /* 子元素上下排列 */
  background-color: #e5e1fc;
}
// 标题样式
.title-box {
  height: rpx(50);
}
.box-icon {
  width: 100%;
  height: 100%;
  flex: 1;
  display: flex; // 添加 flex 布局
  align-items: center; // 垂直居中
  color: black; // 设置图标颜色为白色
  padding-left: rpx(15);
  font-size: rpx(10); // 设置图标大小，可按需调整
  cursor: pointer; // 添加鼠标指针样式
}
.box-icon .left-icon {
  margin-left: rpx(10);
  margin-right: rpx(5); // 设置图标和文字之间的间距 ;
}
// 内容样式
.content-box {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
}
.small-box {
  width: rpx(180);
  height: rpx(110);
  margin-top: rpx(10);
  margin-left: rpx(15);
  border-radius: rpx(6);
  border: 1px solid white;
  background: rgba($color: #ffffff, $alpha: 0.5);
  position: relative;
  cursor: pointer; // 添加鼠标指针样式
}
.people-box {
  position: absolute;
  top: rpx(-30);
  overflow: hidden;
  width: rpx(180);
  height: rpx(140);
  border-radius: rpx(6);
  margin-bottom: rpx(5);
  // background-color: pink;
  display: flex;
  justify-content: center;
  align-items: center;
}
.people-box img {
  width: rpx(100);
  margin-top: rpx(75);
}
.people-title {
  font-size: rpx(8);
  margin-top: rpx(110);
}
.small-box span {
  color: black;
  font-size: rpx(8);
}
</style>
