<template>
  <div class="floating-header">
    <div class="header-left">
      <div class="system-title">
        <!-- 按照实际路径引入logo.jpg -->
        <img 
          src="@/views/childRoom/logo.png" 
          class="logo-icon mr-2" 
          alt="系统logo"
          style="width:24px; height:24px; object-fit:contain;"  
        >
        <span class="title-text blue-title">网络化任务规划系统</span>
      </div>
      
      <!-- 顶部导航菜单 -->
      <div class="top-nav-menu">
        <div 
            v-for="item in topNavItems" 
            :key="item.id"
            class="top-nav-item"
            :class="{ active: activeTopNav === item.id }"
            @click="selectTopNav(item)"
          >
            <i :class="item.icon" class="nav-icon"></i>
            <span class="nav-text">{{ item.name }}</span>
            
            <!-- 文件下拉菜单 -->
            <el-dropdown 
              v-if="item.id === 'file'" 
              trigger="click" 
              placement="bottom-start"
              :hide-on-click="false"
              class="file-dropdown"
            >
              <div class="dropdown-trigger"></div>
              <el-dropdown-menu slot="dropdown" class="file-dropdown-menu">
                <!-- 新增新建计划和打开选项 -->
                <el-dropdown-item @click.native="newPlan">新建计划</el-dropdown-item>
                <el-dropdown-item @click.native="openPlan">打开</el-dropdown-item>
                <el-dropdown-item @click.native="savePlan">保存</el-dropdown-item>
                
                <!-- 导入二级菜单 -->
                <el-dropdown-item class="submenu-item">
                  <span>导入</span>
                  <el-dropdown 
                    trigger="hover" 
                    placement="right-start"
                    class="submenu-dropdown"
                  >
                    <div class="submenu-trigger"></div>
                    <el-dropdown-menu slot="dropdown" class="submenu">
                      <el-dropdown-item @click.native="importPlanFile">导入计划</el-dropdown-item>
                      <el-dropdown-item @click.native="importACD">导入ACD</el-dropdown-item>
                      <el-dropdown-item @click.native="importATO">导入ATO</el-dropdown-item>
                      <el-dropdown-item @click.native="importLayer">导入图层</el-dropdown-item>
                      <el-dropdown-item @click.native="importRoute">导入航线</el-dropdown-item>
                    </el-dropdown-menu>
                  </el-dropdown>
                </el-dropdown-item>
                
                <el-dropdown-item @click.native="exportPlan">导出</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            
            <!-- 编辑下拉菜单 -->
            <el-dropdown 
              v-if="item.id === 'edit'" 
              trigger="click" 
              placement="bottom-start"
              :hide-on-click="false"
              class="file-dropdown"
            >
              <div class="dropdown-trigger"></div>
              <el-dropdown-menu slot="dropdown" class="file-dropdown-menu">
                <el-dropdown-item @click.native="routeEdit">航线编辑</el-dropdown-item>
                <el-dropdown-item @click.native="militaryMarking">军事标绘</el-dropdown-item>
                <el-dropdown-item @click.native="iconEdit">图标编辑</el-dropdown-item>
                <el-dropdown-item @click.native="attributeEdit">属性修改</el-dropdown-item>
                
                <!-- 推演编辑二级菜单 -->
                <el-dropdown-item class="submenu-item">
                  <span>推演编辑</span>
                  <el-dropdown 
                    trigger="hover" 
                    placement="right-start"
                    class="submenu-dropdown"
                  >
                    <div class="submenu-trigger"></div>
                    <el-dropdown-menu slot="dropdown" class="submenu">
                      <el-dropdown-item @click.native="timeSettings">时间设置</el-dropdown-item>
                      <el-dropdown-item @click.native="aircraftSettings">机型设置</el-dropdown-item>
                      <el-dropdown-item @click.native="keyEventEdit">关键事件编辑</el-dropdown-item>
                      <el-dropdown-item @click.native="missileLaunch">导弹发射</el-dropdown-item>
                    </el-dropdown-menu>
                  </el-dropdown>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            
            <!-- 视图下拉菜单 -->
            <el-dropdown 
              v-if="item.id === 'view'" 
              trigger="click" 
              placement="bottom-start"
              :hide-on-click="false"
              class="file-dropdown"
            >
              <div class="dropdown-trigger"></div>
              <el-dropdown-menu slot="dropdown" class="file-dropdown-menu">
                <el-dropdown-item @click.native="toggle2D3D">2D/3D切换</el-dropdown-item>
                <el-dropdown-item @click.native="toggleRuler">显示/隐藏标尺</el-dropdown-item>
                <el-dropdown-item @click.native="toggleGrid">网格</el-dropdown-item>
                <el-dropdown-item @click.native="toggleScale">比例尺</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            
            <!-- 地图下拉菜单 -->
            <el-dropdown 
              v-if="item.id === 'map'" 
              trigger="click" 
              placement="bottom-start"
              :hide-on-click="false"
              class="file-dropdown"
            >
              <div class="dropdown-trigger"></div>
              <el-dropdown-menu slot="dropdown" class="file-dropdown-menu">
                <el-dropdown-item @click.native="loadTerrain">加载/切换地形</el-dropdown-item>
                <el-dropdown-item @click.native="changeProjection">投影</el-dropdown-item>
                <el-dropdown-item @click.native="loadAeroChart">航空图</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            
            <!-- 空域下拉菜单 -->
            <el-dropdown 
              v-if="item.id === 'airspace'" 
              trigger="click" 
              placement="bottom-start"
              :hide-on-click="false"
              class="file-dropdown"
            >
              <div class="dropdown-trigger"></div>
              <el-dropdown-menu slot="dropdown" class="file-dropdown-menu">
                <el-dropdown-item @click.native="powerZone">威力区</el-dropdown-item>
                <el-dropdown-item @click.native="threatZone">威胁区</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            
            <!-- 工具下拉菜单 -->
            <el-dropdown 
              v-if="item.id === 'tools'" 
              trigger="click" 
              placement="bottom-start"
              :hide-on-click="false"
              class="file-dropdown"
            >
              <div class="dropdown-trigger"></div>
              <el-dropdown-menu slot="dropdown" class="file-dropdown-menu">
                <el-dropdown-item @click.native="routeCalculation">航线计算</el-dropdown-item>
                <el-dropdown-item @click.native="conflictDisplay">冲突显示</el-dropdown-item>
                <el-dropdown-item @click.native="dataMaterials">数据资料</el-dropdown-item>
                <el-dropdown-item @click.native="coordinateConversion">坐标换算</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            
            <!-- 选项下拉菜单 -->
            <el-dropdown 
              v-if="item.id === 'options'" 
              trigger="click" 
              placement="bottom-start"
              :hide-on-click="false"
              class="file-dropdown"
            >
              <div class="dropdown-trigger"></div>
              <el-dropdown-menu slot="dropdown" class="file-dropdown-menu">
                <!-- 设置二级菜单 -->
                <el-dropdown-item class="submenu-item">
                  <span>设置</span>
                  <el-dropdown 
                    trigger="hover" 
                    placement="right-start"
                    class="submenu-dropdown"
                  >
                    <div class="submenu-trigger"></div>
                    <el-dropdown-menu slot="dropdown" class="submenu">
                      <el-dropdown-item @click.native="pageLayout">页面布局</el-dropdown-item>
                      <el-dropdown-item @click.native="dataStoragePath">数据存储路径</el-dropdown-item>
                      <el-dropdown-item @click.native="externalParams">外部参数</el-dropdown-item>
                      <el-dropdown-item @click.native="toggleAirport">显示/隐藏机场</el-dropdown-item>
                      <el-dropdown-item @click.native="toggleLandmark">显示/隐藏地标</el-dropdown-item>
                      <el-dropdown-item @click.native="toggleRoute">显示/隐藏航线</el-dropdown-item>
                    </el-dropdown-menu>
                  </el-dropdown>
                </el-dropdown-item>
                <el-dropdown-item @click.native="systemDescription">系统说明</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            
            <!-- 收藏下拉菜单 -->
            <el-dropdown 
              v-if="item.id === 'favorites'" 
              trigger="click" 
              placement="bottom-start"
              :hide-on-click="false"
              class="file-dropdown"
            >
              <div class="dropdown-trigger"></div>
              <el-dropdown-menu slot="dropdown" class="file-dropdown-menu">
                <el-dropdown-item @click.native="layerFavorites">图层收藏</el-dropdown-item>
                <el-dropdown-item @click.native="routeFavorites">航线收藏</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </div>
      </div>

      <div class="header-right">
        <!-- 作战信息区域 -->
        <div class="combat-info-group">
          <!-- 房间编号 -->
          <div class="info-box">
            <i class="el-icon-office-building info-icon"></i>
            <div class="info-content">
              <div class="info-label">房间编号</div>
              <div class="info-value">{{ roomCode }}</div>
            </div>
          </div>
          
          <!-- 在线人数 -->
          <div class="info-box" @click="showOnlineMembersDialog">
            <i class="el-icon-user info-icon"></i>
            <div class="info-content">
              <div class="info-label">在线人数</div>
              <div class="info-value">{{ onlineCount }}人</div>
            </div>
          </div>
          
          <!-- 作战时间 -->
          <div class="info-box">
            <i class="el-icon-timer info-icon"></i>
            <div class="info-content">
              <div class="info-label">作战时间</div>
              <div class="info-value">{{ combatTime }}</div>
            </div>
          </div>
          
          <!-- 天文时间 -->
          <div class="info-box">
            <i class="el-icon-sunny info-icon"></i>
            <div class="info-content">
              <div class="info-label">天文时间</div>
              <div class="info-value">{{ astroTime }}</div>
            </div>
          </div>
        </div>
        
        <!-- 用户状态区域 -->
        <div class="user-status-area">
          <!-- 用户头像 -->
          <el-avatar :size="32" :src="userAvatar" class="user-avatar" />
        </div>
      </div>
      
      <!-- 威力区弹窗 -->
      <power-zone-dialog 
        v-model="powerZoneDialogVisible" 
        :power-zone="currentPowerZone"
        @save="savePowerZone"
      />
      
      <!-- 比例尺弹窗 -->
      <scale-dialog 
        v-model="scaleDialogVisible" 
        :scale="currentScale"
        @save="saveScale"
      />
      
      <!-- 外部参数弹窗 -->
      <external-params-dialog 
        v-model="externalParamsDialogVisible" 
        :external-params="currentExternalParams"
        @save="saveExternalParams"
        @import-airport="importAirport"
        @import-route-data="importRoute"
        @import-landmark="importLandmark"
      />
  </div>
</template>

<script>
import PowerZoneDialog from '../dialogs/PowerZoneDialog'
import ScaleDialog from '../dialogs/ScaleDialog'
import ExternalParamsDialog from '../dialogs/ExternalParamsDialog'

export default {
  name: 'TopHeader',
  components: {
    PowerZoneDialog,
    ScaleDialog,
    ExternalParamsDialog
  },
  props: {
    roomCode: {
      type: String,
      default: 'JTF-7-ALPHA'
    },
    onlineCount: {
      type: Number,
      default: 30
    },
    combatTime: {
      type: String,
      default: 'K+01:30:45'
    },
    astroTime: {
      type: String,
      default: ''
    },
    userAvatar: {
      type: String,
      default: 'https://cube.elemecdn.com/0/88dd03f9bf287d08f58fbcf58fddbf4a8c6/avatar.png'
    }
  },
  data() {
    return {
      activeTopNav: 'file',
      powerZoneDialogVisible: false,
      currentPowerZone: {},
      scaleDialogVisible: false,
      currentScale: {},
      externalParamsDialogVisible: false,
      currentExternalParams: {},
      topNavItems: [
        { id: 'file', name: '文件', icon: 'el-icon-document' },
        { id: 'edit', name: '编辑', icon: 'el-icon-edit' },
        { id: 'view', name: '视图', icon: 'el-icon-view' },
        { id: 'map', name: '地图', icon: 'el-icon-map-location' },
        { id: 'airspace', name: '空域', icon: 'el-icon-s-grid' },
        { id: 'tools', name: '工具', icon: 'el-icon-setting' },
        { id: 'options', name: '选项', icon: 'el-icon-s-tools' },
        { id: 'favorites', name: '收藏', icon: 'el-icon-star-on' }
      ]
    }
  },
  methods: {
    selectTopNav(item) {
      this.$emit('select-nav', item)
    },
    
    // 文件下拉菜单新增方法
    newPlan() {
      this.$emit('new-plan')
    },
    openPlan() {
      this.$emit('open-plan')
    },
    
    // 文件下拉菜单方法
    savePlan() {
      this.$emit('save-plan')
    },
    
    importPlanFile() {
      this.$emit('import-plan-file')
    },
    
    importACD() {
      this.$emit('import-acd')
    },
    
    importATO() {
      this.$emit('import-ato')
    },
    
    importLayer() {
      this.$emit('import-layer')
    },
    
    importRoute() {
      this.$emit('import-route')
    },
    
    exportPlan() {
      this.$emit('export-plan')
    },
    
    // 编辑下拉菜单方法
    routeEdit() {
      this.$emit('route-edit')
    },
    
    militaryMarking() {
      this.$emit('military-marking')
    },
    
    iconEdit() {
      this.$emit('icon-edit')
    },
    
    attributeEdit() {
      this.$emit('attribute-edit')
    },
    
    timeSettings() {
      this.$emit('time-settings')
    },
    
    aircraftSettings() {
      this.$emit('aircraft-settings')
    },
    
    keyEventEdit() {
      this.$emit('key-event-edit')
    },
    
    missileLaunch() {
      this.$emit('missile-launch')
    },
    
    // 视图下拉菜单方法
    toggle2D3D() {
      this.$emit('toggle-2d-3d')
    },
    
    toggleRuler() {
      this.$emit('toggle-ruler')
    },
    
    toggleGrid() {
      this.$emit('toggle-grid')
    },
    
    toggleScale() {
      this.scaleDialogVisible = true
      this.currentScale = {}
    },
    
    // 地图下拉菜单方法
    loadTerrain() {
      this.$emit('load-terrain')
    },
    
    changeProjection() {
      this.$emit('change-projection')
    },
    
    loadAeroChart() {
      this.$emit('load-aero-chart')
    },
    
    // 空域下拉菜单方法
    powerZone() {
      this.powerZoneDialogVisible = true
      this.currentPowerZone = {}
    },
    
    threatZone() {
      this.$emit('threat-zone')
    },
    
    // 工具下拉菜单方法
    routeCalculation() {
      this.$emit('route-calculation')
    },
    
    conflictDisplay() {
      this.$emit('conflict-display')
    },
    
    dataMaterials() {
      this.$emit('data-materials')
    },
    
    coordinateConversion() {
      this.$emit('coordinate-conversion')
    },
    
    // 选项下拉菜单方法
    pageLayout() {
      this.$emit('page-layout')
    },
    
    dataStoragePath() {
      this.$emit('data-storage-path')
    },
    
    externalParams() {
      this.externalParamsDialogVisible = true
      this.currentExternalParams = {}
    },
    
    toggleAirport() {
      this.$emit('toggle-airport')
    },
    
    toggleLandmark() {
      this.$emit('toggle-landmark')
    },
    
    toggleRoute() {
      this.$emit('toggle-route')
    },
    
    systemDescription() {
      this.$emit('system-description')
    },
    
    // 收藏下拉菜单方法
    layerFavorites() {
      this.$emit('layer-favorites')
    },
    
    routeFavorites() {
      this.$emit('route-favorites')
    },
    
    showOnlineMembersDialog() {
      this.$emit('show-online-members')
    },
    
    // 威力区弹窗方法
    savePowerZone(powerZone) {
      this.$emit('save-power-zone', powerZone)
    },
    
    // 比例尺弹窗方法
    saveScale(scale) {
      this.$emit('save-scale', scale)
    },
    
    // 外部参数弹窗方法
    saveExternalParams(externalParams) {
      this.$emit('save-external-params', externalParams)
    },
    
    importAirport(path) {
      this.$emit('import-airport', path)
    },
    
    importRoute(path) {
      this.$emit('import-route-data', path)
    },
    
    importLandmark(path) {
      this.$emit('import-landmark', path)
    }
  }
}
</script>

<style scoped>
/* 顶部导航栏 - 最终优化设计 */
.floating-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 100;
  backdrop-filter: blur(15px);
  /* 调整背景为更透明的白色 */
  background: rgba(255, 255, 255, 0.3);
  border-bottom: 1px solid rgba(0, 138, 255, 0.1);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 25px;
  flex: 1;
}

.system-title {
  display: flex;
  align-items: center;
  font-size: 18px;
  font-weight: bold;
  min-width: 180px;
}

/* 新增logo图片样式，保证显示效果 */
.logo-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.system-title i {
  font-size: 24px;
  color: #008aff;
}

.blue-title {
  color: #008aff !important;
}

/* 顶部导航菜单 - 优化为简洁文字效果 */
.top-nav-menu {
  display: flex;
  gap: 0;
  flex: 1;
  overflow-x: auto;
  max-width: 800px;
  padding: 5px 0;
  scrollbar-width: thin;
}

.top-nav-menu::-webkit-scrollbar {
  height: 3px;
}

.top-nav-menu::-webkit-scrollbar-track {
  background: rgba(0, 138, 255, 0.1);
  border-radius: 2px;
}

.top-nav-menu::-webkit-scrollbar-thumb {
  background: rgba(0, 138, 255, 0.3);
  border-radius: 2px;
}

.top-nav-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #333;
  transition: all 0.3s;
  border-radius: 4px;
  white-space: nowrap;
  min-width: 60px;
  justify-content: center;
  margin: 0 1px;
  position: relative;
  flex-shrink: 0;
}

.top-nav-item:hover {
  color: #008aff;
  background: rgba(0, 138, 255, 0.05);
}

.top-nav-item.active {
  color: #008aff;
  font-weight: 700;
}

/* 移除了蓝色指示条 */
.top-nav-item.active::after {
  display: none;
}

.nav-icon {
  font-size: 16px;
  transition: all 0.3s;
}

.top-nav-item:hover .nav-icon,
.top-nav-item.active .nav-icon {
  transform: scale(1.1);
}

.nav-text {
  font-size: 13px;
  font-weight: 600;
  transition: all 0.3s;
}

/* 下拉菜单样式 */
.file-dropdown {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.dropdown-trigger {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.file-dropdown-menu {
  margin-top: 5px;
  margin-bottom: 0;
  border: none;
  border-radius: 6px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(15px);
  /* 下拉菜单也同步调整为更透明的白色 */
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(0, 138, 255, 0.1);
  padding: 0;
  min-width: auto;
  width: fit-content;
}

.file-dropdown-menu .el-dropdown-menu__item {
  padding: 8px 16px;
  font-size: 14px;
  color: #333;
  transition: all 0.2s ease;
  margin: 0;
}

.file-dropdown-menu .el-dropdown-menu__item:hover {
  background: rgba(0, 138, 255, 0.1);
  color: #008aff;
}

.file-dropdown-menu .el-dropdown-menu__item:not(:last-child) {
  border-bottom: 1px solid rgba(0, 138, 255, 0.1);
}

.file-dropdown-menu .el-dropdown-menu__item:last-child {
  border-bottom: none;
}

.submenu-item {
  position: relative;
}

.submenu-dropdown {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.submenu-trigger {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.submenu {
  margin-left: 5px;
  margin-bottom: 0;
  border: none;
  border-radius: 6px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(15px);
  /* 子菜单同步调整透明度 */
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(0, 138, 255, 0.1);
  padding: 0;
  min-width: auto;
  width: fit-content;
}

.submenu .el-dropdown-menu__item {
  padding: 8px 16px;
  font-size: 14px;
  color: #333;
  transition: all 0.2s ease;
  margin: 0;
}

.submenu .el-dropdown-menu__item:hover {
  background: rgba(0, 138, 255, 0.1);
  color: #008aff;
}

.submenu .el-dropdown-menu__item:not(:last-child) {
  border-bottom: 1px solid rgba(0, 138, 255, 0.1);
}

.submenu .el-dropdown-menu__item:last-child {
  border-bottom: none;
}

/* 右侧信息区域 */
.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.combat-info-group {
  display: flex;
  align-items: center;
  gap: 15px;
}

.info-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  /* 信息框也调整为更透明的白色 */
  background: rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
  border: 1px solid rgba(0, 138, 255, 0.05);
}

.info-box:hover {
  background: rgba(0, 138, 255, 0.1);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 138, 255, 0.1);
}

.combat-info-group .info-box:nth-child(3) .info-value {
  color: #409EFF;
  font-weight: 600;
}

.combat-info-group .info-box:nth-child(4) .info-value {
  color: #67c23a;
  font-weight: 600;
}

.info-icon {
  font-size: 20px;
  color: #008aff;
}

.info-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.info-label {
  font-size: 11px;
  color: #666;
}

.info-value {
  font-size: 13px;
  color: #333;
  font-weight: 600;
}

.user-status-area {
  display: flex;
  align-items: center;
}

.user-avatar {
  cursor: pointer;
  transition: all 0.3s;
}

.user-avatar:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
</style>