<template>
  <el-container class="customer-dashboard">
    <el-header>
      <h1>中医药与心理健康</h1>
      <div class="menu-wrapper">
        <el-menu :default-active="activeIndex" mode="horizontal" background-color="#4CAF50" text-color="#fff" active-text-color="#ffd04b">
          <el-menu-item index="/customer/home" @click="$router.push('/customer/home')">首页</el-menu-item>
          <el-sub-menu index="/customer/education">
            <template #title>教育与预防</template>
            <el-menu-item index="/customer/knowledge-base" @click="$router.push('/customer/knowledge-base')">知识库</el-menu-item>
            <el-menu-item index="/customer/wellness-guide" @click="$router.push('/customer/wellness-guide')">养生指南</el-menu-item>
          </el-sub-menu>
          <el-sub-menu index="/customer/assessment">
            <template #title>心理健康评估</template>
            <el-menu-item index="/customer/psychological-test" @click="$router.push('/customer/psychological-test')">心理测试</el-menu-item>
            <el-menu-item index="/customer/questionnaire" @click="$router.push('/customer/questionnaire')">问卷调查</el-menu-item>
          </el-sub-menu>
          <el-menu-item index="/customer/social-circle" @click="$router.push('/customer/social-circle')">匿名分享圈</el-menu-item>
        </el-menu>
      </div>
      <div class="user-avatar-container">
        <el-dropdown>
          <el-avatar :size="40" :src="userAvatar" class="user-avatar" @click="$router.push('/customer/profile')"></el-avatar>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="$router.push('/customer/profile')">个人信息</el-dropdown-item>
              <el-dropdown-item @click="logout" divided>退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </el-header>
    <el-main>
      <router-view></router-view>
    </el-main>
  </el-container>
</template>

<script>
export default {
  name: 'CustomerDashboard',
  data () {
    return {
      userAvatar: require('@/assets/user/1.jpg')
    }
  },
  computed: {
    activeIndex () {
      const path = this.$route.path
      // 设置主菜单路径映射
      if (path.includes('/customer/knowledge-base') || path.includes('/customer/wellness-guide')) {
        return '/customer/education'
      } else if (path.includes('/customer/psychological-test') || path.includes('/customer/questionnaire')) {
        return '/customer/assessment'
      } else {
        return path
      }
    }
  },
  methods: {
    logout () {
      this.$router.push('/login')
    }
  }
}
</script>

<style scoped>
.customer-dashboard {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.el-header {
  background: #4CAF50;
  color: white;
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.menu-wrapper {
  flex: 1;
  display: flex;
  justify-content: center;
  max-width: 80%;
  margin: 0 15px;
}

.el-menu {
  display: flex;
  background-color: transparent !important;
  border: none;
  width: 100%;
  justify-content: center;
}

.el-menu-item {
  font-size: 15px;
  height: 56px;
  line-height: 56px;
  margin: 0 15px;
  padding: 0 10px;
}

.el-sub-menu {
  margin: 0 15px;
}

.el-menu-item.is-active {
  color: #ffd04b !important;
  background-color: rgba(255, 255, 255, 0.2) !important;
}

.el-menu-item:hover {
  background: rgba(255, 255, 255, 0.2) !important;
}

.user-avatar-container {
  display: flex;
  align-items: center;
  margin-left: 10px;
}

.user-avatar {
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
}

.user-avatar:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

@media (max-width: 992px) {
  .el-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 0.5rem;
  }

  .menu-wrapper {
    width: 100%;
    max-width: 100%;
    margin: 10px 0;
  }

  .el-menu {
    width: 100%;
  }

  .el-menu-item, .el-sub-menu {
    margin: 0 5px;
  }

  .user-avatar-container {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    margin-left: 0;
  }
}
</style>
