<template>
  <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
    <div class="container-fluid">
      <NuxtLink class="navbar-brand" to="/">
        <i class="bi bi-clipboard-check me-2"></i>
        주간업무보고
      </NuxtLink>

      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
        <span class="navbar-toggler-icon"></span>
      </button>

      <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav me-auto">
          <li class="nav-item">
            <NuxtLink class="nav-link" to="/" active-class="active">
              <i class="bi bi-house me-1"></i> 대시보드
            </NuxtLink>
          </li>
          <li class="nav-item">
            <NuxtLink class="nav-link" to="/report/weekly" active-class="active">
              <i class="bi bi-journal-text me-1"></i> 주간보고
            </NuxtLink>
          </li>
          <li class="nav-item">
            <NuxtLink class="nav-link" to="/report/summary" active-class="active">
              <i class="bi bi-collection me-1"></i> 취합보고
            </NuxtLink>
          </li>
          <li class="nav-item">
            <NuxtLink class="nav-link" to="/project" active-class="active">
              <i class="bi bi-folder me-1"></i> 프로젝트
            </NuxtLink>
          </li>
          <li class="nav-item">
            <NuxtLink class="nav-link" to="/employee" active-class="active">
              <i class="bi bi-people me-1"></i> 직원관리
            </NuxtLink>
          </li>
          <!-- 관리자 메뉴 (coziny@gmail.com 전용) -->
          <li class="nav-item dropdown" v-if="isAdmin">
            <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">
              <i class="bi bi-gear me-1"></i> 관리자
            </a>
            <ul class="dropdown-menu">
              <li>
                <NuxtLink class="dropdown-item" to="/admin/bulk-import">
                  <i class="bi bi-file-earmark-arrow-up me-2"></i>주간보고 일괄등록
                </NuxtLink>
              </li>
            </ul>
          </li>
        </ul>

        <!-- 사용자 정보 -->
        <div class="d-flex align-items-center" v-if="currentUser">
          <NuxtLink to="/mypage" class="text-white text-decoration-none me-3 user-link">
            <i class="bi bi-person-circle me-1"></i>
            {{ currentUser.employeeName }}
          </NuxtLink>
          <button class="btn btn-outline-light btn-sm" @click="handleLogout">
            <i class="bi bi-box-arrow-right"></i> 로그아웃
          </button>
        </div>
      </div>
    </div>
  </nav>
</template>

<script setup lang="ts">
const { currentUser, logout } = useAuth()
const router = useRouter()

const isAdmin = computed(() => currentUser.value?.employeeEmail === 'coziny@gmail.com')

async function handleLogout() {
  await logout()
  router.push('/login')
}
</script>

<style scoped>
.navbar-brand {
  font-weight: 600;
}
.nav-link {
  padding: 0.5rem 1rem;
}
.nav-link.active {
  font-weight: 500;
}
.user-link {
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  transition: background-color 0.2s;
}
.user-link:hover {
  background-color: rgba(255, 255, 255, 0.1);
}
</style>
