<template>
  <header class="header">
    <div class="header-container">
      <div class="logo">
        <router-link to="/">
          <div class="logo-text">云帆互联</div>
        </router-link>
      </div>
      <nav class="nav-menu">
        <router-link to="/course" :class="{ active: isActive('/course') }">课程学习</router-link>
        <router-link to="/exam" :class="{ active: isActive('/exam') }">在线考试</router-link>
        <router-link to="/practice" :class="{ active: isActive('/practice') }">刷题训练</router-link>
        <router-link to="/activity" :class="{ active: isActive('/activity') }">活动大厅</router-link>
        <router-link to="/mall" :class="{ active: isActive('/mall') }">商城</router-link>
        <router-link to="/announcement" :class="{ active: isActive('/announcement') }">公告</router-link>
        <router-link to="/my" :class="{ active: isActive('/my') }">我的</router-link>
      </nav>
      <div class="user-info">
        <el-dropdown>
          <div class="user-avatar">
            <el-avatar :size="40" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
            <span>{{ userStore.username }}</span>
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item v-if="userStore.isAdmin" @click="router.push('/admin/dashboard')">
                管理后台
              </el-dropdown-item>
              <el-dropdown-item @click="router.push('/my/profile')">个人信息</el-dropdown-item>
              <el-dropdown-item @click="router.push('/my/courses')">我的课程</el-dropdown-item>
              <el-dropdown-item divided @click="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </header>
</template>

<script setup>
import { useRouter, useRoute } from 'vue-router'
import { useUserStore } from '../../stores/user'

const router = useRouter()
const route = useRoute()
const userStore = useUserStore()

const isActive = (path) => {
  return route.path.startsWith(path)
}

const logout = () => {
  userStore.logout()
  router.push('/login')
}
</script>

<style lang="scss" scoped>
.header {
  background-color: #4080ff;
  color: white;
  padding: 0 20px;
  
  .header-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    max-width: 1200px;
    margin: 0 auto;
  }
  
  .logo {
    a {
      display: flex;
      align-items: center;
      color: white;
      text-decoration: none;
      font-size: 20px;
      font-weight: bold;
      
      .logo-text {
        background-color: rgba(255, 255, 255, 0.2);
        padding: 5px 10px;
        border-radius: 4px;
      }
    }
  }
  
  .nav-menu {
    display: flex;
    gap: 20px;
    
    a {
      color: rgba(255, 255, 255, 0.8);
      text-decoration: none;
      padding: 5px 0;
      font-size: 16px;
      position: relative;
      
      &.active, &:hover {
        color: white;
        
        &::after {
          content: '';
          position: absolute;
          bottom: -2px;
          left: 0;
          width: 100%;
          height: 2px;
          background-color: white;
        }
      }
    }
  }
  
  .user-info {
    .user-avatar {
      display: flex;
      align-items: center;
      cursor: pointer;
      
      span {
        margin-left: 8px;
      }
    }
  }
}
</style> 