<template>
  <header class="header">
    <div class="container header-container">
      <router-link to="/" class="logo">Valitov<span>Gaziz</span></router-link>
      <nav class="nav" :class="{ 'nav-open': menuOpen }">
        <router-link to="/" class="nav-link" @click="$emit('toggle-menu')">Главная</router-link>
        <a href="#about" class="nav-link" @click="closeMenu">Обо мне</a>
        <a href="#projects" class="nav-link" @click="closeMenu">Проекты</a>
        <a href="#experience" class="nav-link" @click="closeMenu">Опыт</a>
        <a href="#skills" class="nav-link" @click="closeMenu">Навыки</a>
        <a href="#contact" class="nav-link" @click="closeMenu">Контакты</a>
        <router-link to="/blog" class="nav-link" @click="$emit('toggle-menu')">Блог</router-link>
      </nav>
      <div class="header-actions">
        <button class="theme-toggle" @click="$emit('toggle-theme')" :aria-label="theme === 'dark' ? 'Светлая тема' : 'Тёмная тема'">
          <svg v-if="theme === 'dark'" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg>
          <svg v-else width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/></svg>
        </button>
        <button class="burger" @click="$emit('toggle-menu')" :aria-label="menuOpen ? 'Закрыть меню' : 'Открыть меню'">
          <span></span><span></span><span></span>
        </button>
      </div>
    </div>
  </header>
</template>

<script>
export default {
  name: 'TheHeader',
  props: {
    theme: { type: String, required: true },
    menuOpen: { type: Boolean, default: false },
  },
  emits: ['toggle-theme', 'toggle-menu'],
  methods: {
    closeMenu() {
      if (this.menuOpen) {
        this.$emit('toggle-menu')
      }
    },
  },
}
</script>

<style scoped>
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--header-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  transition: background 0.3s;
}

.header-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 70px;
}

.logo {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.logo span {
  color: var(--accent);
}

.nav {
  display: flex;
  gap: 8px;
}

.nav-link {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 8px;
  transition: all 0.2s;
}

.nav-link:hover,
.router-link-exact-active {
  color: var(--accent);
  background: var(--skill-bg);
}

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

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  transition: all 0.2s;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.burger {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.burger span {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all 0.3s;
}

.menu-open .burger span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.menu-open .burger span:nth-child(2) {
  opacity: 0;
}

.menu-open .burger span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

@media (max-width: 768px) {
  .nav {
    position: fixed;
    top: 70px;
    left: 0;
    right: 0;
    background: var(--bg);
    flex-direction: column;
    padding: 20px;
    gap: 4px;
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s;
    border-bottom: 1px solid var(--border);
    z-index: 999;
  }

  .nav-open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: all;
  }

  .burger {
    display: flex;
  }
}
</style>
