<template>
  <header class="page-header">
    <div class="header-content">
      <div class="header-left">
        <div class="logo-container">
          <img src="@/assets/images/水利logo.png" alt="水利logo" class="water-logo">
        </div>
        <div class="title-container">
          <h1 class="site-title">水利部模型平台<span class="sub-title">可视化模型库</span></h1>
        </div>
      </div>
      
      <nav class="nav-menu">
        <router-link to="/" class="nav-item" :class="{ active: currentRoute === '/' }">首页</router-link>
        <router-link to="/model-management" class="nav-item" :class="{ active: currentRoute === '/model-management' }">模型管理</router-link>
        
        <router-link to="/admin" class="nav-item">后台管理</router-link>
      </nav>
      
      <div class="header-right">
        <div class="current-time">{{ currentTime }}</div>
      </div>
    </div>
  </header>
</template>

<script setup>
import { ref, onMounted, onUnmounted, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'

const currentRoute = ref('')
const currentTime = ref('')

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

const updateTime = () => {
  const now = new Date()
  const year = now.getFullYear()
  const month = String(now.getMonth() + 1).padStart(2, '0')
  const day = String(now.getDate()).padStart(2, '0')
  const hours = String(now.getHours()).padStart(2, '0')
  const minutes = String(now.getMinutes()).padStart(2, '0')
  const seconds = String(now.getSeconds()).padStart(2, '0')
  
  currentTime.value = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}

let timer = null

onMounted(() => {
  currentRoute.value = route.path
  updateTime()
  timer = setInterval(updateTime, 1000)
})

// 监听路由变化
watch(
  () => route.path,
  (newPath) => {
    currentRoute.value = newPath
  }
)

onUnmounted(() => {
  if (timer) {
    clearInterval(timer)
  }
})
</script>

<style scoped>
.page-header {
  background-image: url('@/assets/images/抬头背景.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: white;
  padding: 0.8rem 0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 1000;
  height: 80px;
}

.header-content {
  width: 100%;
  height: 100%;
  padding: 0 1rem 0 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 100%;
  margin: 0 auto;
}

.header-left {
  display: flex;
  align-items: center;
  margin-left: 1rem;
}

.logo-container {
  display: flex;
  align-items: center;
  justify-content: center;
}

.water-logo {
  width: 76px;
  height: 48px;
  object-fit: contain;
  filter: brightness(0) invert(1);
  transition: transform 0.3s ease;
}

.water-logo:hover {
  transform: scale(1.1);
}

.title-container {
  display: flex;
  align-items: center;
  justify-content: center;
}

.site-title {
  font-size: 1.8rem;
  font-weight: 1000;
  margin: 0;
  background: linear-gradient(45deg, #fff, #f0f0f0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.3;
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
}

.sub-title {
  font-size: 1rem;
  font-weight: 600;
  opacity: 0.9;
  background: linear-gradient(45deg, #e6f7ff, #fff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  padding-top: 1rem;
}



.nav-menu {
  display: flex;
  gap: 2rem;
  justify-content: flex-start;
  flex: 2;
  margin-left: 150px;
}

.nav-item {
  color: white;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 400;
  padding: 0.5rem 0.8rem;
  border-radius: 4px;
  transition: all 0.3s ease;
  opacity: 0.9;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  min-width: 60px;
}

.nav-item:nth-child(1)::before {
  content: '';
  width: 16px;
  height: 16px;
  background: url('@/assets/images/首页.png') no-repeat center center;
  background-size: contain;
}

.nav-item:nth-child(2)::before {
  content: '';
  width: 16px;
  height: 16px;
  background: url('@/assets/images/模型管理.png') no-repeat center center;
  background-size: contain;
}

.nav-item:nth-child(3)::before {
  content: '';
  width: 16px;
  height: 16px;
  background: url('@/assets/images/后台管理.png') no-repeat center center;
  background-size: contain;
}

.nav-item:hover {
  opacity: 1;
  transform: translateY(-2px);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.nav-item.active {
  opacity: 1;
  background: rgba(255, 255, 255, 0.2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1.5rem;
  flex: 1;
}

.current-time {
  font-size: 0.875rem;
  font-weight: 400;
  opacity: 0.9;
  font-family: 'Courier New', monospace;
  background: rgba(0, 0, 0, 0.1);
  padding: 0.3rem 0.8rem;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  line-height: 1.5;
}
</style>