<template>
  <div id="app">
    <!-- 只在登录后显示导航栏 -->
    <nav v-if="authStore.isAuthenticated && $route.path !== '/login'" class="main-nav">
      <div class="nav-left">
        <router-link to="/" class="nav-item">首页</router-link>
        <router-link to="/monitor" class="nav-item">监控中心</router-link>
        <router-link to="/government" class="nav-item">政府平台</router-link>
        <router-link to="/finance" class="nav-item">金融服务</router-link>
        <router-link to="/transport" class="nav-item">运输跟踪</router-link>
        <router-link to="/risk" class="nav-item">风险预警</router-link>
        <router-link to="/eco" class="nav-item">生态指标</router-link>
        <router-link to="/gov" class="nav-item">政府监管</router-link>
        <router-link to="/trade" class="nav-item">交易统计</router-link>
        <router-link to="/users" class="nav-item">用户管理</router-link>
      </div>
      
      <div class="nav-right">
        <span class="user-info">
          欢迎，{{ authStore.realName || authStore.username }}
        </span>
        <a-button type="text" @click="handleLogout" class="logout-btn">
          退出登录
        </a-button>
      </div>
    </nav>
    
    <router-view />
  </div>
</template>

<script>
import { useAuthStore } from './store/auth.js'
import { useRouter } from 'vue-router'
import { message } from 'ant-design-vue'

export default {
  name: 'App',
  setup() {
    const authStore = useAuthStore()
    const router = useRouter()
    
    // 处理登出
    const handleLogout = async () => {
      try {
        await authStore.logout()
        message.success('退出登录成功')
        router.push('/login')
      } catch (error) {
        console.error('登出失败:', error)
        message.error('登出失败')
      }
    }
    
    return {
      authStore,
      handleLogout
    }
  }
}
</script>

<style>
#app {
  height: 100vh;
  font-family: 'Microsoft YaHei', '微软雅黑', 'Helvetica Neue', Arial, sans-serif;
  background: #0a1929;
  overflow: hidden;
}

.main-nav {
  padding: 15px 20px;
  background: rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-left {
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 15px;
}

.user-info {
  color: rgba(255, 255, 255, 0.9);
  font-size: 14px;
}

.logout-btn {
  color: rgba(255, 255, 255, 0.8) !important;
  border: 1px solid rgba(255, 255, 255, 0.3) !important;
}

.logout-btn:hover {
  color: #fff !important;
  border-color: #ff4d4f !important;
  background: rgba(255, 77, 79, 0.2) !important;
}

.nav-item {
  color: white;
  text-decoration: none;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: var(--border-radius);
  transition: var(--transition);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-item:hover {
  background: rgba(76, 175, 80, 0.3);
  transform: translateY(-2px);
}

.nav-item.router-link-exact-active {
  background: linear-gradient(45deg, var(--primary-color), var(--primary-dark));
  color: white;
  font-weight: bold;
  border: none;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}

/* 滚动条样式 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: rgba(76, 175, 80, 0.5);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(76, 175, 80, 0.8);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .main-nav {
    padding: 10px;
    gap: 10px;
  }
  
  .nav-item {
    padding: 8px 15px;
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  .nav-item {
    padding: 6px 10px;
    font-size: 12px;
  }
}
</style>