<script setup>
import { useAuthStore } from '../stores/auth'
import { useRouter } from 'vue-router'

const authStore = useAuthStore()
const router = useRouter()

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

<template>
  <header class="app-header">
    <div class="header-container">
      <router-link to="/" class="logo">
        <span class="logo-text">{{ project_name }}</span>
      </router-link>
      
      <nav class="nav-links">
        <template v-if="authStore.isAuthenticated">
          <router-link to="/todos" class="nav-link">Todos</router-link>
          <router-link to="/profile" class="nav-link">{{ authStore.user?.username }}</router-link>
          <button @click="handleLogout" class="btn btn-logout">Logout</button>
        </template>
        <template v-else>
          <router-link to="/login" class="nav-link">Login</router-link>
          <router-link to="/register" class="btn btn-signup">Sign Up</router-link>
        </template>
      </nav>
    </div>
  </header>
</template>

<style scoped>
.app-header {
  background: #092E20;
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
}

.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 60px;
  padding: 0 2rem;
}

.logo {
  text-decoration: none;
  color: white;
  font-weight: 700;
  font-size: 1.25rem;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.nav-link {
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  font-weight: 500;
}

.nav-link:hover {
  color: white;
}

.btn {
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  border: none;
  font-size: 0.9rem;
}

.btn-signup {
  background: white;
  color: #092E20;
}

.btn-signup:hover {
  background: #f0f0f0;
}

.btn-logout {
  background: transparent;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.btn-logout:hover {
  background: rgba(255, 255, 255, 0.1);
}
</style>
