<script setup lang="ts">
import { ref } from 'vue'

interface Props {
  isDarkMode: boolean
}

defineProps<Props>()

defineEmits<{
  toggleSidebar: []
  toggleDarkMode: []
}>()

const isUserMenuOpen = ref(false)
const userName = 'kjh2064'
const userRole = 'Admin'
</script>

<template>
  <header class="app-header">
    <!-- Left: Sidebar Toggle -->
    <div class="header-left">
      <button class="icon-button" @click="$emit('toggleSidebar')" title="Toggle sidebar">
        ☰
      </button>
    </div>

    <!-- Center: Breadcrumb / Title -->
    <div class="header-center">
      <nav class="breadcrumb">
        <span class="breadcrumb-item">Dashboard</span>
      </nav>
    </div>

    <!-- Right: Actions & User Menu -->
    <div class="header-right">
      <!-- Dark Mode Toggle -->
      <button
        class="icon-button"
        @click="$emit('toggleDarkMode')"
        :title="`Switch to ${isDarkMode ? 'light' : 'dark'} mode`"
      >
        {{ isDarkMode ? '☀️' : '🌙' }}
      </button>

      <!-- Notifications -->
      <button class="icon-button" title="Notifications">
        🔔
        <span class="badge">2</span>
      </button>

      <!-- User Menu -->
      <div class="user-menu-wrapper">
        <button
          class="user-button"
          @click="isUserMenuOpen = !isUserMenuOpen"
        >
          <span class="user-avatar">👤</span>
          <span class="user-info">
            <span class="user-name">{{ userName }}</span>
            <span class="user-role">{{ userRole }}</span>
          </span>
          <span class="chevron">{{ isUserMenuOpen ? '▲' : '▼' }}</span>
        </button>

        <!-- Dropdown Menu -->
        <div v-if="isUserMenuOpen" class="user-menu-dropdown">
          <a href="#" class="menu-item">
            <span>👤</span> Profile
          </a>
          <a href="#" class="menu-item">
            <span>⚙️</span> Settings
          </a>
          <a href="#" class="menu-item">
            <span>📖</span> Help & Feedback
          </a>
          <hr class="menu-divider" />
          <a href="#" class="menu-item logout">
            <span>🚪</span> Logout
          </a>
        </div>
      </div>
    </div>
  </header>
</template>

<style scoped>
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-3) var(--spacing-4);
  background-color: var(--color-background-primary);
  border-bottom: var(--border-width-1) solid var(--color-border-primary);
  gap: var(--spacing-4);
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
}

.header-center {
  flex: 1;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.breadcrumb-item {
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
}

.icon-button {
  position: relative;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: var(--border-radius-base);
  background-color: var(--color-background-secondary);
  color: var(--color-text-primary);
  cursor: pointer;
  font-size: 18px;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-button:hover {
  background-color: var(--color-background-hover);
}

.icon-button:active {
  background-color: var(--color-background-active);
}

.badge {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  background-color: var(--color-danger-500);
  color: white;
  border-radius: var(--border-radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-menu-wrapper {
  position: relative;
}

.user-button {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
  padding: var(--spacing-2) var(--spacing-3);
  border: var(--border-width-1) solid var(--color-border-secondary);
  border-radius: var(--border-radius-base);
  background-color: var(--color-background-secondary);
  color: var(--color-text-primary);
  cursor: pointer;
  font-size: var(--font-size-sm);
  transition: all var(--transition-fast);
}

.user-button:hover {
  background-color: var(--color-background-hover);
  border-color: var(--color-border-primary);
}

.user-avatar {
  font-size: 20px;
  line-height: 1;
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
}

.user-name {
  display: block;
  font-weight: var(--font-weight-medium);
  font-size: var(--font-size-sm);
}

.user-role {
  display: block;
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
}

.chevron {
  font-size: 12px;
  transition: transform var(--transition-fast);
}

.user-menu-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: var(--spacing-2);
  min-width: 200px;
  background-color: var(--color-background-primary);
  border: var(--border-width-1) solid var(--color-border-primary);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-index-dropdown);
  overflow: hidden;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
  padding: var(--spacing-3);
  color: var(--color-text-primary);
  text-decoration: none;
  font-size: var(--font-size-sm);
  transition: all var(--transition-fast);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.menu-item:hover {
  background-color: var(--color-background-secondary);
}

.menu-item span:first-child {
  font-size: 16px;
  flex-shrink: 0;
}

.menu-divider {
  margin: var(--spacing-1) 0;
  border: none;
  border-top: var(--border-width-1) solid var(--color-border-secondary);
}

.menu-item.logout {
  color: var(--color-danger-600);
}

.menu-item.logout:hover {
  background-color: var(--color-danger-50);
}

@media (max-width: 768px) {
  .app-header {
    padding: var(--spacing-2) var(--spacing-3);
    gap: var(--spacing-2);
  }

  .header-center {
    display: none;
  }

  .user-info {
    display: none;
  }

  .icon-button {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
}
</style>
