<template>
  <header class="top-bar">
    <div class="logo-area">
      <span class="app-name">数富AI-亚马逊</span>
      <a href="/home" class="btn-home">返回首页</a>
    </div>

    <nav class="nav-tabs">
      <div class="nav-tab-group">
        <div
          v-for="group in navGroups"
          :key="group.label"
          class="nav-dropdown"
          :class="{ active: group.items.some(item => item.key === active) }"
        >
          <button type="button" class="nav-dropdown-trigger">
            <span>{{ group.label }}</span>
            <span class="nav-dropdown-arrow">▾</span>
          </button>
          <div class="nav-dropdown-menu">
            <a
              v-for="item in group.items"
              :key="item.key"
              :href="item.href"
              class="nav-dropdown-item"
              :class="{ active: active === item.key }"
            >
              {{ item.label }}
            </a>
          </div>
        </div>
      </div>
    </nav>

    <div class="top-right"></div>
  </header>
</template>

<script setup lang="ts">
const props = defineProps<{
  active: 'brand' | 'dedupe' | 'convert' | 'split' | 'delete-brand'
}>()

const active = props.active

const navGroups = [
  {
    label: '前端工具',
    items: [
      { key: 'brand', label: '品牌检测', href: '/brand' },
      { key: 'dedupe', label: '数据去重', href: '/new_web_source/dedupe.html' },
      { key: 'split', label: '数据拆分', href: '/new_web_source/split.html' },
      { key: 'convert', label: '格式转换', href: '/new_web_source/convert.html' },
    ],
  },
  {
    label: '运营工具',
    items: [
      { key: 'delete-brand', label: '删除指定ASIN和品牌', href: '/new_web_source/delete-brand.html' },
    ],
  },
] as const
</script>

<style scoped>
.top-bar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 20px;
  background: #111;
  border-bottom: 1px solid #2a2a2a;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.app-name {
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
}

.btn-home {
  color: #d2d2d2;
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
}

.btn-home:hover {
  color: #fff;
}

.nav-tabs {
  flex: 1;
  display: flex;
  justify-content: center;
  min-width: 0;
}

.nav-tab-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.nav-dropdown {
  position: relative;
}

.nav-dropdown-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 112px;
  height: 38px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  color: #8d8d8d;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-dropdown:hover .nav-dropdown-trigger,
.nav-dropdown.active .nav-dropdown-trigger {
  color: #b9d6ff;
  background: rgba(77, 126, 189, 0.14);
}

.nav-dropdown.active .nav-dropdown-trigger {
  background: rgba(77, 126, 189, 0.24);
  border-color: rgba(91, 148, 219, 0.35);
  color: #6caeff;
}

.nav-dropdown-arrow {
  font-size: 11px;
  line-height: 1;
}

.nav-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 220px;
  padding: 8px;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  background: #171717;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  display: none;
  z-index: 20;
}

.nav-dropdown:hover .nav-dropdown-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-dropdown-item {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  color: #b8b8b8;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s ease;
}

.nav-dropdown-item:hover {
  color: #e8f2ff;
  background: rgba(77, 126, 189, 0.14);
}

.nav-dropdown-item.active {
  color: #6caeff;
  background: rgba(77, 126, 189, 0.24);
}

.top-right {
  width: 120px;
  flex-shrink: 0;
}

@media (max-width: 1100px) {
  .top-bar {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
    padding: 16px 20px;
  }

  .nav-tabs {
    width: 100%;
    justify-content: flex-start;
  }

  .nav-tab-group {
    width: 100%;
    justify-content: flex-start;
  }

  .nav-dropdown-menu {
    left: 0;
    right: auto;
  }

  .top-right {
    display: none;
  }
}
</style>
