<script setup>
import { ref, onMounted } from 'vue'
import { Sun, Moon } from 'lucide-vue-next'

defineEmits(['toggleSidebar'])

const isDark = ref(true)

const setTheme = (dark) => {
  isDark.value = dark
  const theme = dark ? 'dark' : 'light'
  document.documentElement.dataset.theme = theme
  localStorage.setItem('theme', theme)
}

const toggleTheme = () => {
  setTheme(!isDark.value)
}

onMounted(() => {
  const savedTheme = localStorage.getItem('theme')
  if (savedTheme) {
    setTheme(savedTheme === 'dark')
  } else {
    setTheme(true)
  }
})
</script>

<template>
  <header class="app-header glass-panel unselectable">
    <div class="header-content">
      <div class="header-left">
        <button
          class="menu-btn"
          @click="$emit('toggleSidebar')"
          aria-label="Toggle Menu"
          title="Toggle Menu"
          v-ripple
        >
          <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
            <line x1="3" y1="12" x2="21" y2="12"></line>
            <line x1="3" y1="6" x2="21" y2="6"></line>
            <line x1="3" y1="18" x2="21" y2="18"></line>
          </svg>
        </button>
        <router-link to="/" class="app-title">Tools App</router-link>
      </div>

      <button
        class="btn-neon nav-btn icon-only"
        @click="toggleTheme"
        :title="isDark ? 'Switch to light mode' : 'Switch to dark mode'"
        v-ripple
      >
        <Sun v-if="isDark" :size="20" />
        <Moon v-else :size="20" />
      </button>
    </div>
  </header>
</template>

<style scoped>
.app-header {
  /* Remove hardcoded colors and use theme variables */
  background: var(--header-bg);
  color: var(--text-color);
  height: var(--header-height);
  padding: 0 1rem;
  display: flex;
  align-items: center;
  /* box-shadow handled by glass-panel class */
  position: sticky;
  top: 0;
  z-index: 100;
  border-left: none;
  border-right: none;
  border-top: none;
  border-radius: 0;
}

.header-content {
  width: 100%;
  padding: 0;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.menu-btn {
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
}

.menu-btn:hover {
  background-color: var(--button-hover-bg);
}

.app-title {
  margin: 0;
  font-size: 1.5rem;
  background: var(--title-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-decoration: none;
  font-weight: bold;
}
</style>
