<template>
  <header class="top-header">
    <div class="page-title">
      <h2>{{ title }}</h2>
    </div>
    <div class="header-actions">
      <LanguageSwitcher />
      <a-dropdown>
        <div class="user-avatar">
          <img src="/images/backgrounds/avatar-default.svg" :alt="$t('dashboard.userAvatar')" />
          <DownOutlined class="arrow-down" />
        </div>
        <template #overlay>
          <a-menu @click="({ key }) => handleUserCommand(key)">
            <a-menu-item key="exitAdmin">
              {{ $t('admin.exitAdmin') }}
            </a-menu-item>
          </a-menu>
        </template>
      </a-dropdown>
    </div>
  </header>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { DownOutlined } from '@ant-design/icons-vue'
import LanguageSwitcher from '@/components/LanguageSwitcher.vue'

defineProps({
  title: {
    type: String,
    required: true
  }
})

const router = useRouter()

const handleUserCommand = (command) => {
  if (command === 'exitAdmin') {
    router.push('/profile')
  }
}
</script>

<style scoped>
.top-header {
  background: var(--bg-elevated, #1A1D2E);
  border-bottom: 1px solid var(--border-subtle, rgba(255,255,255,0.06));
  padding: var(--space-4, 16px) var(--space-6, 24px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,0.05));
}

.page-title h2 {
  margin: 0;
  font-size: var(--text-xl, 20px);
  font-weight: var(--font-semibold, 600);
  color: var(--text-primary, #E2E8F0);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 20px;
}

.user-avatar {
  display: flex;
  align-items: center;
  gap: var(--space-2, 8px);
  cursor: pointer;
  padding: var(--space-1, 4px) var(--space-2, 8px);
  border-radius: var(--radius-sm, 6px);
  transition: var(--transition-all, all 0.2s);
}

.user-avatar:hover {
  background: var(--bg-hover, rgba(255,255,255,0.06));
}

.user-avatar img {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full, 50%);
  object-fit: cover;
}

.user-avatar .arrow-down {
  font-size: var(--text-xs, 12px);
  color: var(--text-tertiary, #64748B);
}
</style>
